diff --git a/snippets/fsharp/System/Base64FormattingOptions/Overview/ToBase64String.fs b/snippets/fsharp/System/Base64FormattingOptions/Overview/ToBase64String.fs
new file mode 100644
index 00000000000..6be3888435d
--- /dev/null
+++ b/snippets/fsharp/System/Base64FormattingOptions/Overview/ToBase64String.fs
@@ -0,0 +1,54 @@
+module ToBase64String
+
+//
+open System
+
+let displayArray (arr: 'a[]) =
+ printfn "The array:"
+ printf "{ "
+ for i = 0 to arr.GetUpperBound(0) - 1 do
+ printf $"{arr[i]}, "
+ if (i + 1) % 10 = 0 then
+ printf "\n "
+ printfn $"{arr[arr.GetUpperBound 0]} }}\n"
+
+// Define an array of 20 elements and display it.
+let arr = Array.zeroCreate 20
+let mutable value = 1
+for i = 0 to arr.GetUpperBound 0 do
+ arr[i] <- value
+ value <- value * 2 + 1
+displayArray arr
+
+// Convert the array of integers to a byte array.
+let bytes = Array.zeroCreate (arr.Length * 4)
+for i = 0 to arr.Length - 1 do
+ Array.Copy(BitConverter.GetBytes(arr[i]), 0, bytes, i * 4, 4)
+
+// Encode the byte array using Base64 encoding
+let base64 = Convert.ToBase64String bytes
+printfn "The encoded string: "
+printfn $"{base64}\n"
+
+// Convert the string back to a byte array.
+let newBytes = Convert.FromBase64String base64
+
+// Convert the byte array back to an integer array.
+let newArr = Array.zeroCreate (newBytes.Length / 4)
+for i = 0 to newBytes.Length / 4 - 1 do
+ newArr[i] <- BitConverter.ToInt32(newBytes, i * 4)
+
+displayArray newArr
+
+// The example displays the following output:
+// The array:
+// { 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023,
+// 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575 }
+//
+// The encoded string:
+// AQAAAAMAAAAHAAAADwAAAB8AAAA/AAAAfwAAAP8AAAD/AQAA/wMAAP8HAAD/DwAA/x8AAP8/AAD/fwAA//8AAP//AQD//wMA//8HAP//DwA=
+//
+// The array:
+// { 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023,
+// 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575 }
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Base64FormattingOptions/Overview/ToBase64String2.fs b/snippets/fsharp/System/Base64FormattingOptions/Overview/ToBase64String2.fs
new file mode 100644
index 00000000000..bc18b5b67c7
--- /dev/null
+++ b/snippets/fsharp/System/Base64FormattingOptions/Overview/ToBase64String2.fs
@@ -0,0 +1,27 @@
+module ToBase64String2
+
+//
+open System
+
+// Define a byte array.
+let bytes = [| 2uy; 4uy; 6uy; 8uy; 10uy; 12uy; 14uy; 16uy; 18uy; 20uy |]
+printfn $"The byte array:\n {BitConverter.ToString bytes}\n"
+
+// Convert the array to a base 64 string.
+let s = Convert.ToBase64String bytes
+printfn $"The base 64 string:\n {s}\n"
+
+// Restore the byte array.
+let newBytes = Convert.FromBase64String s
+printfn $"The restored byte array:\n {BitConverter.ToString newBytes}\n"
+
+// The example displays the following output:
+// The byte array:
+// 02-04-06-08-0A-0C-0E-10-12-14
+//
+// The base 64 string:
+// AgQGCAoMDhASFA==
+//
+// The restored byte array:
+// 02-04-06-08-0A-0C-0E-10-12-14
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Base64FormattingOptions/Overview/ToBase64String3.fs b/snippets/fsharp/System/Base64FormattingOptions/Overview/ToBase64String3.fs
new file mode 100644
index 00000000000..f130e8aee0c
--- /dev/null
+++ b/snippets/fsharp/System/Base64FormattingOptions/Overview/ToBase64String3.fs
@@ -0,0 +1,44 @@
+module ToBase64String3
+
+//
+open System
+
+// Define a byte array.
+let bytes = Array.init 100 (fun i -> i + 1 |> byte)
+let originalTotal = Array.sumBy int bytes
+
+// Display summary information about the array.
+printfn "The original byte array:"
+printfn $" Total elements: {bytes.Length}"
+printfn $" Length of String Representation: {BitConverter.ToString(bytes).Length}"
+printfn $" Sum of elements: {originalTotal:N0}\n"
+
+// Convert the array to a base 64 string.
+let s =
+ Convert.ToBase64String(bytes, Base64FormattingOptions.InsertLineBreaks)
+
+printfn $"The base 64 string:\n {s}\n"
+
+// Restore the byte array.
+let newBytes = Convert.FromBase64String s
+let newTotal = Array.sumBy int newBytes
+
+// Display summary information about the restored array.
+printfn $" Total elements: {newBytes.Length}"
+printfn $" Length of String Representation: {BitConverter.ToString(newBytes).Length}"
+printfn $" Sum of elements: {newTotal:N0}"
+
+// The example displays the following output:
+// The original byte array:
+// Total elements: 100
+// Length of String Representation: 299
+// Sum of elements: 5,050
+//
+// The base 64 string:
+// AQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5
+// Ojs8PT4/QEFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaW1xdXl9gYWJjZA==
+//
+// Total elements: 100
+// Length of String Representation: 299
+// Sum of elements: 5,050
+//
diff --git a/snippets/fsharp/System/Base64FormattingOptions/Overview/fs.fsproj b/snippets/fsharp/System/Base64FormattingOptions/Overview/fs.fsproj
new file mode 100644
index 00000000000..14f814a3403
--- /dev/null
+++ b/snippets/fsharp/System/Base64FormattingOptions/Overview/fs.fsproj
@@ -0,0 +1,11 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/Byte/Overview/ToByte5.fs b/snippets/fsharp/System/Byte/Overview/ToByte5.fs
new file mode 100644
index 00000000000..d998f07f0b5
--- /dev/null
+++ b/snippets/fsharp/System/Byte/Overview/ToByte5.fs
@@ -0,0 +1,33 @@
+module ToByte5
+
+//
+open System
+
+let values =
+ [| null; ""; "0xC9"; "C9"; "101"; "16.3"; "$12"
+ "$12.01"; "-4"; "1,032"; "255"; " 16 " |]
+
+for value in values do
+ try
+ let number = Convert.ToByte(value)
+ printfn $"""'%A{value}' --> {number}"""
+ with
+ | :? FormatException ->
+ printfn $"Bad Format: '%A{value}'"
+ | :? OverflowException ->
+ printfn $"OverflowException: '{value}'"
+
+// The example displays the following output:
+// '' --> 0
+// Bad Format: ''
+// Bad Format: '0xC9'
+// Bad Format: 'C9'
+// '101' --> 101
+// Bad Format: '16.3'
+// Bad Format: '$12'
+// Bad Format: '$12.01'
+// OverflowException: '-4'
+// Bad Format: '1,032'
+// '255' --> 255
+// ' 16 ' --> 16
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Byte/Overview/fs.fsproj b/snippets/fsharp/System/Byte/Overview/fs.fsproj
new file mode 100644
index 00000000000..dd40b557dce
--- /dev/null
+++ b/snippets/fsharp/System/Byte/Overview/fs.fsproj
@@ -0,0 +1,13 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/Byte/Overview/tobyte1.fs b/snippets/fsharp/System/Byte/Overview/tobyte1.fs
new file mode 100644
index 00000000000..e06090622e2
--- /dev/null
+++ b/snippets/fsharp/System/Byte/Overview/tobyte1.fs
@@ -0,0 +1,200 @@
+module tobyte1
+
+open System
+
+let convertBoolean () =
+ //
+ let falseFlag = false
+ let trueFlag = true
+
+ printfn $"{falseFlag} converts to {Convert.ToByte falseFlag}."
+ printfn $"{trueFlag} converts to {Convert.ToByte trueFlag}."
+ // The example displays the following output:
+ // False converts to 0.
+ // True converts to 1.
+ //
+
+let convertChar () =
+ //
+ let chars = [| 'a'; 'z'; '\u0007'; '\u03FF' |]
+ for ch in chars do
+ try
+ let result = Convert.ToByte ch
+ printfn $"{ch} is converted to {result}."
+ with :? OverflowException ->
+ printfn $"Unable to convert u+{Convert.ToInt16 ch:X4} to a byte."
+ // The example displays the following output:
+ // a is converted to 97.
+ // z is converted to 122.
+ // is converted to 7.
+ // Unable to convert u+03FF to a byte.
+ //
+
+let convertInt16 () =
+ //
+ let numbers = [| Int16.MinValue; -1s; 0s; 121s; 340s; Int16.MaxValue |]
+ for number in numbers do
+ try
+ let result = Convert.ToByte number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"The {number.GetType().Name} value {number} is outside the range of the Byte type."
+ // The example displays the following output:
+ // The Int16 value -32768 is outside the range of the Byte type.
+ // The Int16 value -1 is outside the range of the Byte type.
+ // Converted the Int16 value 0 to the Byte value 0.
+ // Converted the Int16 value 121 to the Byte value 121.
+ // The Int16 value 340 is outside the range of the Byte type.
+ // The Int16 value 32767 is outside the range of the Byte type.
+ //
+
+let convertInt32 () =
+ //
+ let numbers = [| Int32.MinValue; -1; 0; 121; 340; Int32.MaxValue |]
+ for number in numbers do
+ try
+ let result = Convert.ToByte number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"The {number.GetType().Name} value {number} is outside the range of the Byte type."
+ // The example displays the following output:
+ // The Int32 value -2147483648 is outside the range of the Byte type.
+ // The Int32 value -1 is outside the range of the Byte type.
+ // Converted the Int32 value 0 to the Byte value 0.
+ // Converted the Int32 value 121 to the Byte value 121.
+ // The Int32 value 340 is outside the range of the Byte type.
+ // The Int32 value 2147483647 is outside the range of the Byte type.
+ //
+
+let convertInt64 () =
+ //
+ let numbers = [| Int64.MinValue; -1L; 0L; 121L; 34L; Int64.MaxValue |]
+ for number in numbers do
+ try
+ let result = Convert.ToByte number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"The {number.GetType().Name} value {number} is outside the range of the Byte type."
+ // The example displays the following output:
+ // The Int64 value -9223372036854775808 is outside the range of the Byte type.
+ // The Int64 value -1 is outside the range of the Byte type.
+ // Converted the Int64 value 0 to the Byte value 0.
+ // Converted the Int64 value 121 to the Byte value 121.
+ // The Int64 value 340 is outside the range of the Byte type.
+ // The Int64 value 9223372036854775807 is outside the range of the Byte type.
+ //
+
+let convertObject () =
+ //
+ let values: obj[] =
+ [| true; -12; 163; 935; 'x'; "104"; "103.0"
+ "-1"; "1.00e2"; "One"; 1.00e2 |]
+ for value in values do
+ try
+ let result = Convert.ToByte value
+ printfn $"Converted the {value.GetType().Name} value {value} to the {result.GetType().Name} value {result}."
+ with
+ | :? OverflowException ->
+ printfn $"The {value.GetType().Name} value {value} is outside the range of the Byte type."
+ | :? FormatException ->
+ printfn $"The {value.GetType().Name} value {value} is not in a recognizable format."
+ | :? InvalidCastException ->
+ printfn $"No conversion to a Byte exists for the {value.GetType().Name} value {value}."
+ // The example displays the following output:
+ // Converted the Boolean value True to the Byte value 1.
+ // The Int32 value -12 is outside the range of the Byte type.
+ // Converted the Int32 value 163 to the Byte value 163.
+ // The Int32 value 935 is outside the range of the Byte type.
+ // Converted the Char value x to the Byte value 120.
+ // Converted the String value 104 to the Byte value 104.
+ // The String value 103.0 is not in a recognizable format.
+ // The String value -1 is outside the range of the Byte type.
+ // The String value 1.00e2 is not in a recognizable format.
+ // The String value One is not in a recognizable format.
+ // Converted the Double value 100 to the Byte value 100.
+ //
+
+let convertSByte () =
+ //
+ let numbers = [| SByte.MinValue; -1y; 0y; 10y; SByte.MaxValue |]
+ for number in numbers do
+ try
+ let result = Convert.ToByte number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"The {number.GetType().Name} value {number} is outside the range of the Byte type."
+ // The example displays the following output:
+ // The SByte value -128 is outside the range of the Byte type.
+ // The SByte value -1 is outside the range of the Byte type.
+ // Converted the SByte value 0 to the Byte value 0.
+ // Converted the SByte value 10 to the Byte value 10.
+ // Converted the SByte value 127 to the Byte value 127.
+ //
+
+let convertUInt16 () =
+ //
+ let numbers = [| UInt16.MinValue; 121us; 340us; UInt16.MaxValue |]
+ for number in numbers do
+ try
+ let result = Convert.ToByte number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"The {number.GetType().Name} value {number} is outside the range of the Byte type."
+ // The example displays the following output:
+ // Converted the UInt16 value 0 to the Byte value 0.
+ // Converted the UInt16 value 121 to the Byte value 121.
+ // The UInt16 value 340 is outside the range of the Byte type.
+ // The UInt16 value 65535 is outside the range of the Byte type.
+ //
+
+let convertUInt32 () =
+ //
+ let numbers = [| UInt32.MinValue; 121u; 340u; UInt32.MaxValue |]
+ for number in numbers do
+ try
+ let result = Convert.ToByte number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"The {number.GetType().Name} value {number} is outside the range of the Byte type."
+ // The example displays the following output:
+ // Converted the UInt32 value 0 to the Byte value 0.
+ // Converted the UInt32 value 121 to the Byte value 121.
+ // The UInt32 value 340 is outside the range of the Byte type.
+ // The UInt32 value 4294967295 is outside the range of the Byte type.
+ //
+
+let convertUInt64 () =
+ //
+ let numbers= [| UInt64.MinValue; 121uL; 340uL; UInt64.MaxValue |]
+ for number in numbers do
+ try
+ let result = Convert.ToByte number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"The {number.GetType().Name} value {number} is outside the range of the Byte type."
+ // The example displays the following output:
+ // Converted the UInt64 value 0 to the Byte value 0.
+ // Converted the UInt64 value 121 to the Byte value 121.
+ // The UInt64 value 340 is outside the range of the Byte type.
+ // The UInt64 value 18446744073709551615 is outside the range of the Byte type.
+ //
+
+convertBoolean ()
+printfn "-----"
+convertChar ()
+printfn "-----"
+convertInt16 ()
+printfn "-----"
+convertInt32 ()
+printfn "-----"
+convertInt64 ()
+printfn "-----"
+convertObject ()
+printfn "-----"
+convertSByte ()
+printfn "-----"
+convertUInt16 ()
+printfn "-----"
+convertUInt32 ()
+printfn "-----"
+convertUInt64 ()
diff --git a/snippets/fsharp/System/Byte/Overview/tobyte2.fs b/snippets/fsharp/System/Byte/Overview/tobyte2.fs
new file mode 100644
index 00000000000..d66d23cce68
--- /dev/null
+++ b/snippets/fsharp/System/Byte/Overview/tobyte2.fs
@@ -0,0 +1,78 @@
+module tobyte2
+
+//
+open System
+
+let bases = [ 2; 8; 10; 16 ]
+let values =
+ [| "-1"; "1"; "08"; "0F"; "11"; "12"; "30"
+ "101"; "255"; "FF"; "10000000"; "80" |]
+
+for numBase in bases do
+ printfn $"Base {numBase}:"
+ for value in values do
+ try
+ let number = Convert.ToByte(value, numBase)
+ printfn $" Converted '{value}' to {number}."
+ with
+ | :? FormatException ->
+ printfn $" '{value}' is not in the correct format for a base {numBase} byte value."
+ | :? OverflowException ->
+ printfn $" '{value}' is outside the range of the Byte type."
+ | :? ArgumentException ->
+ printfn $" '{value}' is invalid in base {numBase}."
+
+// The example displays the following output:
+// Base 2:
+// '-1' is invalid in base 2.
+// Converted '1' to 1.
+// '08' is not in the correct format for a base 2 conversion.
+// '0F' is not in the correct format for a base 2 conversion.
+// Converted '11' to 3.
+// '12' is not in the correct format for a base 2 conversion.
+// '30' is not in the correct format for a base 2 conversion.
+// Converted '101' to 5.
+// '255' is not in the correct format for a base 2 conversion.
+// 'FF' is not in the correct format for a base 2 conversion.
+// Converted '10000000' to 128.
+// '80' is not in the correct format for a base 2 conversion.
+// Base 8:
+// '-1' is invalid in base 8.
+// Converted '1' to 1.
+// '08' is not in the correct format for a base 8 conversion.
+// '0F' is not in the correct format for a base 8 conversion.
+// Converted '11' to 9.
+// Converted '12' to 10.
+// Converted '30' to 24.
+// Converted '101' to 65.
+// Converted '255' to 173.
+// 'FF' is not in the correct format for a base 8 conversion.
+// '10000000' is outside the range of the Byte type.
+// '80' is not in the correct format for a base 8 conversion.
+// Base 10:
+// '-1' is outside the range of the Byte type.
+// Converted '1' to 1.
+// Converted '08' to 8.
+// '0F' is not in the correct format for a base 10 conversion.
+// Converted '11' to 11.
+// Converted '12' to 12.
+// Converted '30' to 30.
+// Converted '101' to 101.
+// Converted '255' to 255.
+// 'FF' is not in the correct format for a base 10 conversion.
+// '10000000' is outside the range of the Byte type.
+// Converted '80' to 80.
+// Base 16:
+// '-1' is invalid in base 16.
+// Converted '1' to 1.
+// Converted '08' to 8.
+// Converted '0F' to 15.
+// Converted '11' to 17.
+// Converted '12' to 18.
+// Converted '30' to 48.
+// '101' is outside the range of the Byte type.
+// '255' is outside the range of the Byte type.
+// Converted 'FF' to 255.
+// '10000000' is outside the range of the Byte type.
+// Converted '80' to 128.
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Byte/Overview/tobyte3.fs b/snippets/fsharp/System/Byte/Overview/tobyte3.fs
new file mode 100644
index 00000000000..54c40338010
--- /dev/null
+++ b/snippets/fsharp/System/Byte/Overview/tobyte3.fs
@@ -0,0 +1,184 @@
+module tobyte3
+
+//
+open System
+open System.Globalization
+
+type SignBit =
+ | Negative = -1
+ | Zero = 0
+ | Positive = 1
+
+[]
+type ByteString =
+ val mutable private value: string
+
+ val mutable Sign : SignBit
+ member this.Value
+ with get () = this.value
+ and set (value: string) =
+ if value.Trim().Length > 2 then
+ invalidArg "value" "The string representation of a byte cannot have more than two characters"
+ else
+ this.value <- value
+
+ // IConvertible implementations.
+ interface IConvertible with
+ member _.GetTypeCode() =
+ TypeCode.Object
+
+ member this.ToBoolean(provider: IFormatProvider) =
+ this.Sign <> SignBit.Zero
+
+ member this.ToByte(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ raise (OverflowException $"{Convert.ToSByte(this.value, 16)} is out of range of the Byte type.")
+ else
+ Byte.Parse(this.value, NumberStyles.HexNumber)
+
+ member this.ToChar(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ raise (OverflowException $"{Convert.ToSByte(this.value, 16)} is out of range of the Char type.")
+ else
+ let byteValue = Byte.Parse(this.value, NumberStyles.HexNumber)
+ Convert.ToChar byteValue
+
+ member _.ToDateTime(provider: IFormatProvider) =
+ raise (InvalidCastException "ByteString to DateTime conversion is not supported.")
+
+ member this.ToDecimal(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ let byteValue = SByte.Parse(this.Value, NumberStyles.HexNumber)
+ Convert.ToDecimal byteValue
+ else
+ let byteValue = Byte.Parse(this.Value, NumberStyles.HexNumber)
+ Convert.ToDecimal byteValue
+
+ member this.ToDouble(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ Convert.ToDouble(SByte.Parse(this.value, NumberStyles.HexNumber))
+ else
+ Convert.ToDouble(Byte.Parse(this.value, NumberStyles.HexNumber))
+
+ member this.ToInt16(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ Convert.ToInt16(SByte.Parse(this.value, NumberStyles.HexNumber))
+ else
+ Convert.ToInt16(Byte.Parse(this.value, NumberStyles.HexNumber))
+
+ member this.ToInt32(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ Convert.ToInt32(SByte.Parse(this.value, NumberStyles.HexNumber))
+ else
+ Convert.ToInt32(Byte.Parse(this.value, NumberStyles.HexNumber))
+
+ member this.ToInt64(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ Convert.ToInt64(SByte.Parse(this.value, NumberStyles.HexNumber))
+ else
+ Convert.ToInt64(Byte.Parse(this.value, NumberStyles.HexNumber))
+
+ member this.ToSByte(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ try
+ Convert.ToSByte(Byte.Parse(this.value, NumberStyles.HexNumber))
+ with :? OverflowException as e ->
+ raise (OverflowException($"{Byte.Parse(this.value, NumberStyles.HexNumber)} is outside the range of the SByte type.", e))
+ else
+ SByte.Parse(this.value, NumberStyles.HexNumber)
+
+ member this.ToSingle(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ Convert.ToSingle(SByte.Parse(this.value, NumberStyles.HexNumber))
+ else
+ Convert.ToSingle(Byte.Parse(this.value, NumberStyles.HexNumber))
+
+ member this.ToString(provider: IFormatProvider) =
+ "0x" + this.value
+
+ member this.ToType(conversionType: Type, provider: IFormatProvider): obj =
+ let this = this :> IConvertible
+ match Type.GetTypeCode conversionType with
+ | TypeCode.Boolean ->
+ this.ToBoolean null
+ | TypeCode.Byte ->
+ this.ToByte null
+ | TypeCode.Char ->
+ this.ToChar null
+ | TypeCode.DateTime ->
+ this.ToDateTime null
+ | TypeCode.Decimal ->
+ this.ToDecimal null
+ | TypeCode.Double ->
+ this.ToDouble null
+ | TypeCode.Int16 ->
+ this.ToInt16 null
+ | TypeCode.Int32 ->
+ this.ToInt32 null
+ | TypeCode.Int64 ->
+ this.ToInt64 null
+ | TypeCode.Object ->
+ if typeof.Equals conversionType then
+ this
+ else
+ raise (InvalidCastException $"Conversion to a {conversionType.Name} is not supported.")
+ | TypeCode.SByte ->
+ this.ToSByte null
+ | TypeCode.Single ->
+ this.ToSingle null
+ | TypeCode.String ->
+ this.ToString null
+ | TypeCode.UInt16 ->
+ this.ToUInt16 null
+ | TypeCode.UInt32 ->
+ this.ToUInt32 null
+ | TypeCode.UInt64 ->
+ this.ToUInt64 null
+ | _ ->
+ raise (InvalidCastException $"Conversion to {conversionType.Name} is not supported.")
+
+ member this.ToUInt16(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ raise (OverflowException $"{SByte.Parse(this.value, NumberStyles.HexNumber)} is outside the range of the UInt16 type.")
+ else
+ Convert.ToUInt16(Byte.Parse(this.value, NumberStyles.HexNumber))
+
+ member this.ToUInt32(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ raise (OverflowException $"{SByte.Parse(this.value, NumberStyles.HexNumber)} is outside the range of the UInt32 type.")
+ else
+ Convert.ToUInt32(Byte.Parse(this.value, NumberStyles.HexNumber))
+
+ member this.ToUInt64(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ raise (OverflowException $"{SByte.Parse(this.value, NumberStyles.HexNumber)} is outside the range of the UInt64 type.")
+ else
+ Convert.ToUInt64(Byte.Parse(this.value, NumberStyles.HexNumber))
+//
+
+//
+let positiveByte = 216uy
+let negativeByte = -101y
+
+let mutable positiveString = ByteString()
+positiveString.Sign <- Math.Sign positiveByte |> enum
+positiveString.Value <- positiveByte.ToString "X2"
+
+let mutable negativeString = ByteString()
+negativeString.Sign <- Math.Sign negativeByte |> enum
+negativeString.Value <- negativeByte.ToString "X2"
+
+try
+ printfn $"'{positiveString.Value}' converts to {Convert.ToByte positiveString}."
+with :? OverflowException ->
+ printfn $"0x{positiveString.Value} is outside the range of the Byte type."
+
+try
+ printfn $"'{negativeString.Value}' converts to {Convert.ToByte negativeString}."
+with :? OverflowException ->
+ printfn $"0x{negativeString.Value} is outside the range of the Byte type."
+
+// The example displays the following output:
+// 'D8' converts to 216.
+// 0x9B is outside the range of the Byte type.
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Byte/Overview/tobyte4.fs b/snippets/fsharp/System/Byte/Overview/tobyte4.fs
new file mode 100644
index 00000000000..17d7ec7cafe
--- /dev/null
+++ b/snippets/fsharp/System/Byte/Overview/tobyte4.fs
@@ -0,0 +1,43 @@
+module tobyte4
+
+//
+open System
+open System.Globalization
+
+// Create a NumberFormatInfo object and set several of its
+// properties that apply to unsigned bytes.
+let provider = NumberFormatInfo()
+
+// These properties affect the conversion.
+provider.PositiveSign <- "pos "
+provider.NegativeSign <- "neg "
+
+// This property does not affect the conversion.
+// The input string cannot have a decimal separator.
+provider.NumberDecimalSeparator <- "."
+
+// Define an array of numeric strings.
+let numericStrings =
+ [| "234"; "+234"; "pos 234"
+ "234."; "255"; "256"; "-1" |]
+
+for numericString in numericStrings do
+ printf $"'{numericString,-8}' -> "
+ try
+ let number = Convert.ToByte(numericString, provider)
+ printfn $"{number}"
+ with
+ | :? FormatException ->
+ printfn "Incorrect Format"
+ | :? OverflowException ->
+ printfn "Overflows a Byte"
+
+// The example displays the following output:
+// '234 ' -> 234
+// '+234 ' -> Incorrect Format
+// 'pos 234 ' -> 234
+// '234. ' -> Incorrect Format
+// '255 ' -> 255
+// '256 ' -> Overflows a Byte
+// '-1 ' -> Incorrect Format
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ChangeType/changetype00.fs b/snippets/fsharp/System/Convert/ChangeType/changetype00.fs
new file mode 100644
index 00000000000..15025cb762e
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ChangeType/changetype00.fs
@@ -0,0 +1,75 @@
+module changetype00
+
+//
+open System
+open System.Globalization
+
+type InterceptProvider() =
+ interface IFormatProvider with
+ member _.GetFormat(formatType: Type) =
+ if formatType = typeof then
+ printfn " Returning a fr-FR numeric format provider."
+ CultureInfo("fr-FR").NumberFormat
+ elif formatType = typeof then
+ printfn " Returning an en-US date/time format provider."
+ CultureInfo("en-US").DateTimeFormat
+ else
+ printfn $" Requesting a format provider of {formatType.Name}."
+ null
+
+let values: obj[] = [| 103.5; DateTime(2010, 12, 26, 14, 34, 0)|]
+let provider = InterceptProvider()
+
+// Convert value to each of the types represented in TypeCode enum.
+for value in values do
+ // Iterate types in TypeCode enum.
+ for enumType in Enum.GetValues typeof :?> TypeCode[] do
+ match enumType with
+ | TypeCode.DBNull | TypeCode.Empty -> ()
+ | _ ->
+ try
+ printfn $"{value} ({value.GetType().Name}) --> {Convert.ChangeType(value, enumType, provider)} ({enumType})."
+ with
+ | :? InvalidCastException ->
+ printfn $"Cannot convert a {value.GetType().Name} to a {enumType}"
+ | :? OverflowException ->
+ printfn $"Overflow: {value} is out of the range of a {enumType}"
+ printfn ""
+
+// The example displays the following output:
+// 103.5 (Double) --> 103.5 (Object).
+// 103.5 (Double) --> True (Boolean).
+// Cannot convert a Double to a Char
+// 103.5 (Double) --> 104 (SByte).
+// 103.5 (Double) --> 104 (Byte).
+// 103.5 (Double) --> 104 (Int16).
+// 103.5 (Double) --> 104 (UInt16).
+// 103.5 (Double) --> 104 (Int32).
+// 103.5 (Double) --> 104 (UInt32).
+// 103.5 (Double) --> 104 (Int64).
+// 103.5 (Double) --> 104 (UInt64).
+// 103.5 (Double) --> 103.5 (Single).
+// 103.5 (Double) --> 103.5 (Double).
+// 103.5 (Double) --> 103.5 (Decimal).
+// Cannot convert a Double to a DateTime
+// Returning a fr-FR numeric format provider.
+// 103.5 (Double) --> 103,5 (String).
+//
+// 12/26/2010 2:34:00 PM (DateTime) --> 12/26/2010 2:34:00 PM (Object).
+// Cannot convert a DateTime to a Boolean
+// Cannot convert a DateTime to a Char
+// Cannot convert a DateTime to a SByte
+// Cannot convert a DateTime to a Byte
+// Cannot convert a DateTime to a Int16
+// Cannot convert a DateTime to a UInt16
+// Cannot convert a DateTime to a Int32
+// Cannot convert a DateTime to a UInt32
+// Cannot convert a DateTime to a Int64
+// Cannot convert a DateTime to a UInt64
+// Cannot convert a DateTime to a Single
+// Cannot convert a DateTime to a Double
+// Cannot convert a DateTime to a Decimal
+// 12/26/2010 2:34:00 PM (DateTime) --> 12/26/2010 2:34:00 PM (DateTime).
+// Returning an en-US date/time format provider.
+// 12/26/2010 2:34:00 PM (DateTime) --> 12/26/2010 2:34:00 PM (String).
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ChangeType/changetype01.fs b/snippets/fsharp/System/Convert/ChangeType/changetype01.fs
new file mode 100644
index 00000000000..376165fed72
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ChangeType/changetype01.fs
@@ -0,0 +1,18 @@
+module changetype01
+
+//
+open System
+
+let d = -2.345
+let i = Convert.ChangeType(d, TypeCode.Int32) :?> int
+
+printfn $"The Double {d} when converted to an Int32 is {i}"
+
+let s = "12/12/2009"
+let dt = Convert.ChangeType(s, typeof) :?> DateTime
+
+printfn $"The String {s} when converted to a Date is {dt}"
+// The example displays the following output:
+// The Double -2.345 when converted to an Int32 is -2
+// The String 12/12/2009 when converted to a Date is 12/12/2009 12:00:00 AM
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ChangeType/changetype03.fs b/snippets/fsharp/System/Convert/ChangeType/changetype03.fs
new file mode 100644
index 00000000000..0b2f478d0f7
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ChangeType/changetype03.fs
@@ -0,0 +1,169 @@
+module changetype03
+
+//
+open System
+open System.Globalization
+
+type Temperature(temperature: decimal) =
+
+ member _.Celsius = temperature
+
+ member _.Kelvin =
+ temperature + 273.15m
+
+ member _.Fahrenheit =
+ Math.Round(decimal (temperature * 9m / 5m + 32m), 2)
+
+ override _.ToString() =
+ temperature.ToString "N2" + "°C"
+
+ // IConvertible implementations.
+ interface IConvertible with
+ member _.GetTypeCode() =
+ TypeCode.Object
+
+ member _.ToBoolean(provider: IFormatProvider) =
+ temperature <> 0M
+
+ member _.ToByte(provider: IFormatProvider) =
+ if temperature < decimal Byte.MinValue || temperature > decimal Byte.MaxValue then
+ raise (OverflowException $"{temperature} is out of range of the Byte type.")
+ else
+ Decimal.ToByte temperature
+
+ member _.ToChar(provider: IFormatProvider) =
+ raise (InvalidCastException "Temperature to Char conversion is not supported.")
+
+ member _.ToDateTime(provider: IFormatProvider) =
+ raise (InvalidCastException "Temperature to DateTime conversion is not supported.")
+
+ member _.ToDecimal(provider: IFormatProvider) =
+ temperature
+
+ member _.ToDouble(provider: IFormatProvider) =
+ Decimal.ToDouble temperature
+
+ member _.ToInt16(provider: IFormatProvider) =
+ if temperature < decimal Int16.MinValue || temperature > decimal Int16.MaxValue then
+ raise (OverflowException $"{temperature} is out of range of the Int16 type.")
+ else
+ Decimal.ToInt16 temperature
+
+ member _.ToInt32(provider: IFormatProvider) =
+ if temperature < decimal Int32.MinValue || temperature > decimal Int32.MaxValue then
+ raise (OverflowException $"{temperature} is out of range of the Int32 type.")
+ else
+ Decimal.ToInt32 temperature
+
+ member _.ToInt64(provider: IFormatProvider) =
+ if temperature < decimal Int64.MinValue || temperature > decimal Int64.MaxValue then
+ raise (OverflowException $"{temperature} is out of range of the Int64 type.")
+ else
+ Decimal.ToInt64 temperature
+
+ member _.ToSByte(provider: IFormatProvider) =
+ if temperature < decimal SByte.MinValue || temperature > decimal SByte.MaxValue then
+ raise (OverflowException $"{temperature} is out of range of the SByte type.")
+ else
+ Decimal.ToSByte temperature
+
+ member _.ToSingle(provider: IFormatProvider) =
+ Decimal.ToSingle temperature
+
+ member _.ToString(provider: IFormatProvider) =
+ temperature.ToString("N2", provider) + "°C"
+
+ member this.ToType(conversionType: Type, provider: IFormatProvider) =
+ let this = this :> IConvertible
+ match Type.GetTypeCode conversionType with
+ | TypeCode.Boolean->
+ this.ToBoolean null
+ | TypeCode.Byte ->
+ this.ToByte null
+ | TypeCode.Char ->
+ this.ToChar null
+ | TypeCode.DateTime ->
+ this.ToDateTime null
+ | TypeCode.Decimal ->
+ this.ToDecimal null
+ | TypeCode.Double ->
+ this.ToDouble null
+ | TypeCode.Int16 ->
+ this.ToInt16 null
+ | TypeCode.Int32 ->
+ this.ToInt32 null
+ | TypeCode.Int64 ->
+ this.ToInt64 null
+ | TypeCode.Object ->
+ if typeof.Equals conversionType then
+ this
+ else
+ raise (InvalidCastException $"Conversion to a {conversionType.Name} is not supported.")
+ | TypeCode.SByte ->
+ this.ToSByte null
+ | TypeCode.Single ->
+ this.ToSingle null
+ | TypeCode.String ->
+ this.ToString provider
+ | TypeCode.UInt16 ->
+ this.ToUInt16 null
+ | TypeCode.UInt32->
+ this.ToUInt32 null
+ | TypeCode.UInt64->
+ this.ToUInt64 null
+ | _ ->
+ raise (InvalidCastException $"Conversion to {conversionType.Name} is not supported.")
+
+ member _.ToUInt16(provider: IFormatProvider) =
+ if temperature < decimal UInt16.MinValue || temperature > decimal UInt16.MaxValue then
+ raise (OverflowException $"{temperature} is out of range of the UInt16 type.")
+ else
+ Decimal.ToUInt16 temperature
+
+ member _.ToUInt32(provider: IFormatProvider) =
+ if temperature < decimal UInt32.MinValue || temperature > decimal UInt32.MaxValue then
+ raise (OverflowException $"{temperature} is out of range of the UInt32 type.")
+ else
+ Decimal.ToUInt32 temperature
+
+ member _.ToUInt64(provider: IFormatProvider) =
+ if temperature < decimal UInt64.MinValue || temperature > decimal UInt64.MaxValue then
+ raise (OverflowException $"{temperature} is out of range of the UInt64 type.")
+ else
+ Decimal.ToUInt64 temperature
+//
+
+//
+let cool = Temperature 5
+let targetTypes =
+ [ typeof; typeof; typeof
+ typeof; typeof; typeof
+ typeof; typeof; typeof;
+ typeof; typeof; typeof; ]
+
+let provider = CultureInfo "fr-FR"
+
+for targetType in targetTypes do
+ try
+ let value = Convert.ChangeType(cool, targetType, provider)
+ printfn $"Converted {cool.GetType().Name} {cool} to {targetType.Name} {value}."
+ with
+ | :? InvalidCastException ->
+ printfn $"Unsupported {cool.GetType().Name} --> {targetType.Name} conversion."
+ | :? OverflowException ->
+ printfn $"{cool} is out of range of the {targetType.Name} type."
+
+// The example dosplays the following output:
+// Converted Temperature 5.00°C to SByte 5.
+// Converted Temperature 5.00°C to Int16 5.
+// Converted Temperature 5.00°C to Int32 5.
+// Converted Temperature 5.00°C to Int64 5.
+// Converted Temperature 5.00°C to Byte 5.
+// Converted Temperature 5.00°C to UInt16 5.
+// Converted Temperature 5.00°C to UInt32 5.
+// Converted Temperature 5.00°C to UInt64 5.
+// Converted Temperature 5.00°C to Decimal 5.
+// Converted Temperature 5.00°C to Single 5.
+// Converted Temperature 5.00°C to Double 5.
+// Converted Temperature 5.00°C to String 5,00°C.
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ChangeType/changetype_enum2.fs b/snippets/fsharp/System/Convert/ChangeType/changetype_enum2.fs
new file mode 100644
index 00000000000..dc1360ad43e
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ChangeType/changetype_enum2.fs
@@ -0,0 +1,31 @@
+module changetype_enum2
+
+//
+open System
+
+type Continent =
+ | Africa = 0
+ | Antarctica = 1
+ | Asia = 2
+ | Australia = 3
+ | Europe = 4
+ | NorthAmerica = 5
+ | SouthAmerica = 6
+
+// Convert a Continent to a Double.
+let cont = Continent.NorthAmerica
+printfn $"{Convert.ChangeType(cont, typeof):N2}"
+
+// Convert a Double to a Continent.
+let number = 6.0
+try
+ printfn $"{Convert.ChangeType(number, typeof)}"
+with :? InvalidCastException ->
+ printfn "Cannot convert a Double to a Continent"
+
+printfn $"{int number |> enum}"
+// The example displays the following output:
+// 5.00
+// Cannot convert a Double to a Continent
+// SouthAmerica
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ChangeType/changetype_nullable.fs b/snippets/fsharp/System/Convert/ChangeType/changetype_nullable.fs
new file mode 100644
index 00000000000..c5842e0c78b
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ChangeType/changetype_nullable.fs
@@ -0,0 +1,17 @@
+module changetype_nullable
+
+//
+open System
+
+let intValue1 = Nullable 12893
+let dValue1 = Convert.ChangeType(intValue1, typeof) :?> double
+printfn $"{intValue1} ({intValue1.GetType().Name})--> {dValue1} ({dValue1.GetType().Name})"
+
+let fValue1 = 16.3478f
+let intValue2 = Nullable(int fValue1)
+printfn $"{fValue1} ({fValue1.GetType().Name})--> {intValue2} ({intValue2.GetType().Name})"
+
+// The example displays the following output:
+// 12893 (Int32)--> 12893 (Double)
+// 16.3478 (Single)--> 16 (Int32)
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ChangeType/changetype_nullable_1.fs b/snippets/fsharp/System/Convert/ChangeType/changetype_nullable_1.fs
new file mode 100644
index 00000000000..7adb5435def
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ChangeType/changetype_nullable_1.fs
@@ -0,0 +1,17 @@
+module changetype_nullable_1
+
+//
+open System
+
+let intValue1 = Nullable 12893
+let dValue1 = Convert.ChangeType(intValue1, typeof, null) :?> double
+printfn $"{intValue1} ({intValue1.GetType().Name})--> {dValue1} ({dValue1.GetType().Name})"
+
+let fValue1 = 16.3478f
+let intValue2 = Nullable(int fValue1)
+printfn $"{fValue1} ({fValue1.GetType().Name})--> {intValue2} ({intValue2.GetType().Name})"
+
+// The example displays the following output:
+// 12893 (Int32)--> 12893 (Double)
+// 16.3478 (Single)--> 16 (Int32)
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ChangeType/convertchangetype.fs b/snippets/fsharp/System/Convert/ChangeType/convertchangetype.fs
new file mode 100644
index 00000000000..9a9eee2f42c
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ChangeType/convertchangetype.fs
@@ -0,0 +1,15 @@
+module convertchangetype
+
+//
+open System
+
+let d = -2.345
+let i = Convert.ChangeType(d, typeof) :?> int
+
+printfn $"The double value {d} when converted to an int becomes {i}"
+
+let s = "12/12/98"
+let dt = Convert.ChangeType(s, typeof) :?> DateTime
+
+printfn $"The string value {s} when converted to a Date becomes {dt}"
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ChangeType/fs.fsproj b/snippets/fsharp/System/Convert/ChangeType/fs.fsproj
new file mode 100644
index 00000000000..178448f5586
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ChangeType/fs.fsproj
@@ -0,0 +1,15 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/DBNull/dbnull1.fs b/snippets/fsharp/System/Convert/DBNull/dbnull1.fs
new file mode 100644
index 00000000000..a58efe34c6b
--- /dev/null
+++ b/snippets/fsharp/System/Convert/DBNull/dbnull1.fs
@@ -0,0 +1,6 @@
+open System
+
+//
+printfn $"{Convert.DBNull.Equals DBNull.Value}"
+// Displays True.
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/DBNull/fs.fsproj b/snippets/fsharp/System/Convert/DBNull/fs.fsproj
new file mode 100644
index 00000000000..3e4caa26aae
--- /dev/null
+++ b/snippets/fsharp/System/Convert/DBNull/fs.fsproj
@@ -0,0 +1,9 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/FromBase64CharArray/class1.fs b/snippets/fsharp/System/Convert/FromBase64CharArray/class1.fs
new file mode 100644
index 00000000000..7f5433f1a9f
--- /dev/null
+++ b/snippets/fsharp/System/Convert/FromBase64CharArray/class1.fs
@@ -0,0 +1,78 @@
+module class1
+
+open System
+open System.IO
+open System.Text
+
+let inputFileName = "fs.fsproj"
+let outputFileName = "out.xml"
+
+//
+let encodeWithCharArray () =
+ try
+ use inFile =
+ new FileStream(inputFileName, FileMode.Open, FileAccess.Read)
+
+ let binaryData =
+ Array.zeroCreate (int inFile.Length)
+
+ inFile.Read(binaryData, 0, int inFile.Length)
+ |> ignore
+
+ // Convert the binary input into Base64 UUEncoded output.
+ // Each 3 byte sequence in the source data becomes a 4 byte
+ // sequence in the character array.
+ let arrayLength =
+ (4. / 3.) * float binaryData.Length |> int64
+
+ // If array length is not divisible by 4, shadow up to the next multiple of 4.
+ let arrayLength =
+ if arrayLength % 4L <> 0L then
+ arrayLength + (4L - arrayLength % 4L)
+ else
+ arrayLength
+
+ let base64CharArray = Array.zeroCreate (int arrayLength)
+
+ Convert.ToBase64CharArray(binaryData, 0, binaryData.Length, base64CharArray, 0)
+ |> ignore
+ // Write the UUEncoded version to the output file.
+ use outFile =
+ new StreamWriter(outputFileName, false, Encoding.ASCII)
+
+ outFile.Write(base64CharArray)
+ outFile.Close()
+ with
+ | :? ArgumentNullException -> printfn "Binary data array is null."
+ | :? ArgumentOutOfRangeException -> printfn "Char Array is not large enough."
+ | e ->
+ // Error creating stream or writing to it.
+ printfn $"{e.Message}"
+//
+
+//
+let decodeWithCharArray () =
+ try
+ let inFile =
+ new StreamReader(inputFileName, Encoding.ASCII)
+
+ let base64CharArray =
+ Array.zeroCreate (int inFile.BaseStream.Length)
+
+ inFile.Read(base64CharArray, 0, (int) inFile.BaseStream.Length)
+ |> ignore
+
+ // Convert the Base64 UUEncoded input into binary output.
+ let binaryData =
+ Convert.FromBase64CharArray(base64CharArray, 0, base64CharArray.Length)
+ // Write out the decoded data.
+ use outFile =
+ new FileStream(outputFileName, FileMode.Create, FileAccess.Write)
+
+ outFile.Write(binaryData, 0, binaryData.Length)
+ with
+ | :? ArgumentNullException -> printfn "Base 64 character array is null."
+ | :? FormatException -> printfn "Base 64 Char Array length is not 4 or is not an even multiple of 4."
+ | e -> printfn $"{e.Message}"
+
+//
diff --git a/snippets/fsharp/System/Convert/FromBase64CharArray/fs.fsproj b/snippets/fsharp/System/Convert/FromBase64CharArray/fs.fsproj
new file mode 100644
index 00000000000..ac94659d404
--- /dev/null
+++ b/snippets/fsharp/System/Convert/FromBase64CharArray/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/FromBase64CharArray/tb64ca.fs b/snippets/fsharp/System/Convert/FromBase64CharArray/tb64ca.fs
new file mode 100644
index 00000000000..30e8a297b81
--- /dev/null
+++ b/snippets/fsharp/System/Convert/FromBase64CharArray/tb64ca.fs
@@ -0,0 +1,80 @@
+module tb64ca
+
+//
+// This example demonstrates the Convert.ToBase64CharArray() and
+// Convert.FromBase64CharArray methods
+open System
+
+let arraysAreEqual (a1: byte[]) (a2: byte[]) =
+ a1.Length = a2.Length &&
+ Array.forall2 (=) a2 a1
+
+let byteArray1 = Array.zeroCreate 256
+let charArray = Array.zeroCreate 352
+let nl = Environment.NewLine
+
+let ruler =
+ $" 1 2 3 4 5 6 7 {nl}" +
+ $"1234567890123456789012345678901234567890123456789012345678901234567890123456{nl}" +
+ "----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+-"
+
+// 1) Initialize and display a Byte array of arbitrary data.
+printfn $"1) Input: A Byte array of arbitrary data.{nl}"
+for i = 0 to byteArray1.Length - 1 do
+ byteArray1[i] <- byte i
+ printf $"{byteArray1[i]:X2} "
+ if (i + 1) % 20 = 0 then
+ printfn ""
+printf $"{nl}{nl}"
+
+// 2) Convert the input Byte array to a Char array, with newlines inserted.
+let charArrayLength =
+ Convert.ToBase64CharArray(byteArray1, 0, byteArray1.Length,
+ charArray, 0, Base64FormattingOptions.InsertLineBreaks)
+printfn "2) Convert the input Byte array to a Char array with newlines."
+printf $" Output: A Char array (length = {charArrayLength}). "
+printfn $"The elements of the array are:{nl}"
+printfn $"{ruler}"
+printfn $"{String charArray}"
+printfn ""
+
+// 3) Convert the Char array back to a Byte array.
+printfn "3) Convert the Char array to an output Byte array."
+let byteArray2 = Convert.FromBase64CharArray(charArray, 0, charArrayLength)
+
+// 4) Are the input and output Byte arrays equivalent?
+printfn $"4) The output Byte array is equal to the input Byte array: {arraysAreEqual byteArray1 byteArray2}"
+
+
+// This example produces the following results:
+// 1) Input: A Byte array of arbitrary data.
+//
+// 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13
+// 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27
+// 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B
+// 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F
+// 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F 60 61 62 63
+// 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F 70 71 72 73 74 75 76 77
+// 78 79 7A 7B 7C 7D 7E 7F 80 81 82 83 84 85 86 87 88 89 8A 8B
+// 8C 8D 8E 8F 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F
+// A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF B0 B1 B2 B3
+// B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF C0 C1 C2 C3 C4 C5 C6 C7
+// C8 C9 CA CB CC CD CE CF D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB
+// DC DD DE DF E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF
+// F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF
+//
+// 2) Convert the input Byte array to a Char array with newlines.
+// Output: A Char array (length = 352). The elements of the array are:
+//
+// 1 2 3 4 5 6 7
+// 1234567890123456789012345678901234567890123456789012345678901234567890123456
+// ----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+-
+// AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4
+// OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3Bx
+// cnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmq
+// q6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj
+// 5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==
+//
+// 3) Convert the Char array to an output Byte array.
+// 4) The output Byte array is equal to the input Byte array: True
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/IsDBNull/Form1.fs b/snippets/fsharp/System/Convert/IsDBNull/Form1.fs
new file mode 100644
index 00000000000..3bfed957f1d
--- /dev/null
+++ b/snippets/fsharp/System/Convert/IsDBNull/Form1.fs
@@ -0,0 +1,85 @@
+open System
+
+open System.Data
+open System.Data.SqlClient
+open System.Collections.Generic
+open System.ComponentModel
+open System.Drawing
+open System.Linq
+open System.Text
+open System.Windows.Forms
+
+type Form1() =
+ inherit Form()
+
+ let connectionString = @"Data Source=RONPET59\SQLEXPRESSInitial Catalog=SurveyDBIntegrated Security=True"
+
+ let grid = new DataGridView()
+
+ member _.CompareForMissing(value: obj) =
+ //
+ DBNull.Value.Equals value
+ //
+
+ //
+ member this.Form1_Load(sender: obj, e: EventArgs) =
+ // Define ADO.NET objects.
+ use conn = new SqlConnection(connectionString)
+ use cmd = new SqlCommand()
+
+ // Open connection, and retrieve dataset.
+ conn.Open()
+
+ // Define Command object.
+ cmd.CommandText <- "Select * From Responses"
+ cmd.CommandType <- CommandType.Text
+ cmd.Connection <- conn
+
+ // Retrieve data reader.
+ let dr = cmd.ExecuteReader()
+
+ let fieldCount = dr.FieldCount
+ let fieldValues = Array.zeroCreate fieldCount
+ let headers =
+ // Get names of fields.
+ Array.init fieldCount dr.GetName
+
+ // Set up data grid.
+ grid.ColumnCount <- fieldCount
+
+ grid.ColumnHeadersDefaultCellStyle.BackColor <- Color.Navy
+ grid.ColumnHeadersDefaultCellStyle.ForeColor <- Color.White
+ grid.ColumnHeadersDefaultCellStyle.Font <- new Font(grid.Font, FontStyle.Bold)
+
+ grid.AutoSizeRowsMode <- DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
+ grid.ColumnHeadersBorderStyle <- DataGridViewHeaderBorderStyle.Single
+ grid.CellBorderStyle <- DataGridViewCellBorderStyle.Single
+ grid.GridColor <- Color.Black
+ grid.RowHeadersVisible <- true
+
+ for columnNumber = 0 to headers.Length - 1 do
+ grid.Columns[columnNumber].Name <- headers[columnNumber]
+
+ // Get data, replace missing values with "NA", and display it.
+ while dr.Read() do
+ dr.GetValues fieldValues |> ignore
+ for fieldCounter = 0 to fieldCount do
+ if Convert.IsDBNull fieldValues[fieldCounter] then
+ fieldValues[fieldCounter] <- "NA"
+ grid.Rows.Add fieldValues |> ignore
+ dr.Close()
+
+ override _.Dispose(disposing) =
+ if disposing then
+ grid.Dispose();
+ base.Dispose disposing
+ //
+
+
+/// The main entry point for the application.
+[]
+let main _ =
+ Application.EnableVisualStyles()
+ Application.SetCompatibleTextRenderingDefault false
+ Application.Run(new Form1())
+ 0
diff --git a/snippets/fsharp/System/Convert/IsDBNull/fs.fsproj b/snippets/fsharp/System/Convert/IsDBNull/fs.fsproj
new file mode 100644
index 00000000000..e2d3e21313c
--- /dev/null
+++ b/snippets/fsharp/System/Convert/IsDBNull/fs.fsproj
@@ -0,0 +1,13 @@
+
+
+ Exe
+ net6.0-windows
+ true
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/Overview/NonDecimal1.fs b/snippets/fsharp/System/Convert/Overview/NonDecimal1.fs
new file mode 100644
index 00000000000..c2ffa63e902
--- /dev/null
+++ b/snippets/fsharp/System/Convert/Overview/NonDecimal1.fs
@@ -0,0 +1,18 @@
+module NonDecimal
+
+//
+open System
+
+let baseValues = [ 2; 8; 10; 16 ]
+let value = Int16.MaxValue
+for baseValue in baseValues do
+ let s = Convert.ToString(value, baseValue)
+ let value2 = Convert.ToInt16(s, baseValue)
+ printfn $"{value} --> {s} (base {baseValue}) --> {value2}"
+
+// The example displays the following output:
+// 32767 --> 111111111111111 (base 2) --> 32767
+// 32767 --> 77777 (base 8) --> 32767
+// 32767 --> 32767 (base 10) --> 32767
+// 32767 --> 7fff (base 16) --> 32767
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/Overview/converter.fs b/snippets/fsharp/System/Convert/Overview/converter.fs
new file mode 100644
index 00000000000..71bd7eaaf66
--- /dev/null
+++ b/snippets/fsharp/System/Convert/Overview/converter.fs
@@ -0,0 +1,48 @@
+module converter
+
+open System
+
+//
+let dNumber = 23.15
+
+try
+ // Returns 23
+ Convert.ToInt32 dNumber
+ |> ignore
+with :? OverflowException ->
+ printfn "Overflow in double to int conversion."
+// Returns True
+let bNumber = System.Convert.ToBoolean dNumber
+
+// Returns "23.15"
+let strNumber = System.Convert.ToString dNumber
+
+try
+ // Returns '2'
+ System.Convert.ToChar strNumber[0]
+ |> ignore
+with
+| :? ArgumentNullException ->
+ printfn "String is null"
+| :? FormatException ->
+ printfn "String length is greater than 1."
+
+// System.Console.ReadLine() returns a string and it
+// must be converted.
+let newInteger =
+ try
+ printfn "Enter an integer:"
+ System.Convert.ToInt32(Console.ReadLine())
+ with
+ | :? ArgumentNullException ->
+ printfn "String is null."
+ 0
+ | :? FormatException ->
+ printfn "String does not consist of an optional sign followed by a series of digits."
+ 0
+ | :? OverflowException ->
+ printfn "Overflow in string to int conversion."
+ 0
+
+printfn $"Your integer as a double is {System.Convert.ToDouble newInteger}"
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/Overview/fs.fsproj b/snippets/fsharp/System/Convert/Overview/fs.fsproj
new file mode 100644
index 00000000000..17ca4cd2f22
--- /dev/null
+++ b/snippets/fsharp/System/Convert/Overview/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToBase64String/fs.fsproj b/snippets/fsharp/System/Convert/ToBase64String/fs.fsproj
new file mode 100644
index 00000000000..6b275756596
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToBase64String/fs.fsproj
@@ -0,0 +1,9 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToBase64String/tb64s.fs b/snippets/fsharp/System/Convert/ToBase64String/tb64s.fs
new file mode 100644
index 00000000000..ec652f5671d
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToBase64String/tb64s.fs
@@ -0,0 +1,92 @@
+//
+// This example demonstrates the Convert.ToBase64String() and
+// Convert.FromBase64String() methods
+open System
+
+let arraysAreEqual (a1: byte[]) (a2: byte[]) =
+ a1.Length = a2.Length &&
+ Array.forall2 (=) a1 a2
+
+let step1 = "1) The input is a byte array (inArray) of arbitrary data."
+let step2 = "2) Convert a subarray of the input data array to a base 64 string."
+let step3 = "3) Convert the entire input data array to a base 64 string."
+let step4 = "4) The two methods in steps 2 and 3 produce the same result: {0}"
+let step5 = "5) Convert the base 64 string to an output byte array (outArray)."
+let step6 = "6) The input and output arrays, inArray and outArray, are equal: {0}"
+let nl = Environment.NewLine
+
+let ruler =
+ $" 1 2 3 4 5 6 7 {nl}" +
+ $"1234567890123456789012345678901234567890123456789012345678901234567890123456{nl}" +
+ $"----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+-{nl}"
+
+// 1) Display an arbitrary array of input data (inArray). The data could be
+// derived from user input, a file, an algorithm, etc.
+
+printfn $"{step1}\n"
+
+let inArray =
+ [| for i = 0 to 255 do
+ printf $"{i:X2} "
+ if (i + 1) % 20 = 0 then
+ printfn ""
+ byte i |]
+printf $"{nl}{nl}"
+
+// 2) Convert a subarray of the input data to a base64 string. In this case,
+// the subarray is the entire input data array. New lines (CRLF) are inserted.
+
+printfn $"{step2}"
+let s2 = Convert.ToBase64String(inArray, 0, inArray.Length, Base64FormattingOptions.InsertLineBreaks)
+printfn $"{nl}{ruler}{s2}{nl}"
+
+// 3) Convert the input data to a base64 string. In this case, the entire
+// input data array is converted by default. New lines (CRLF) are inserted.
+
+printfn $"{step3}"
+let s3 = Convert.ToBase64String(inArray, Base64FormattingOptions.InsertLineBreaks)
+
+// 4) Test whether the methods in steps 2 and 3 produce the same result.
+printfn $"{step4} {s2.Equals s3}"
+
+// 5) Convert the base 64 string to an output array (outArray).
+printfn $"{step5}"
+let outArray = Convert.FromBase64String s2
+
+// 6) Is outArray equal to inArray?
+printfn $"{step6} {arraysAreEqual inArray outArray}"
+
+
+// This example produces the following results:
+// 1) The input is a byte array (inArray) of arbitrary data.
+//
+// 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13
+// 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27
+// 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B
+// 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F
+// 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F 60 61 62 63
+// 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F 70 71 72 73 74 75 76 77
+// 78 79 7A 7B 7C 7D 7E 7F 80 81 82 83 84 85 86 87 88 89 8A 8B
+// 8C 8D 8E 8F 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F
+// A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF B0 B1 B2 B3
+// B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF C0 C1 C2 C3 C4 C5 C6 C7
+// C8 C9 CA CB CC CD CE CF D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB
+// DC DD DE DF E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF
+// F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF
+//
+// 2) Convert a subarray of the input data array to a base 64 string.
+//
+// 1 2 3 4 5 6 7
+// 1234567890123456789012345678901234567890123456789012345678901234567890123456
+// ----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+-
+// AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4
+// OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3Bx
+// cnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmq
+// q6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj
+// 5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w=
+//
+// 3) Convert the entire input data array to a base 64 string.
+// 4) The two methods in steps 2 and 3 produce the same result: True
+// 5) Convert the base 64 string to an output byte array (outArray).
+// 6) The input and output arrays, inArray and outArray, are equal: True
+//
diff --git a/snippets/fsharp/System/Convert/ToBoolean/ToBoolean1.fs b/snippets/fsharp/System/Convert/ToBoolean/ToBoolean1.fs
new file mode 100644
index 00000000000..cbc1e6e3958
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToBoolean/ToBoolean1.fs
@@ -0,0 +1,25 @@
+module ToBoolean1
+
+//
+open System
+
+let values =
+ [| null; String.Empty; "true"; "TrueString"
+ "False"; " false "; "-1"; "0" |]
+
+for value in values do
+ try
+ printfn $"Converted '{value}' to {Convert.ToBoolean value}."
+
+ with :? FormatException ->
+ printfn $"Unable to convert '{value}' to a Boolean."
+// The example displays the following output:
+// Converted '' to False.
+// Unable to convert '' to a Boolean.
+// Converted 'true' to True.
+// Unable to convert 'TrueString' to a Boolean.
+// Converted 'False' to False.
+// Converted ' false ' to False.
+// Unable to convert '-1' to a Boolean.
+// Unable to convert '0' to a Boolean.
+//
diff --git a/snippets/fsharp/System/Convert/ToBoolean/fs.fsproj b/snippets/fsharp/System/Convert/ToBoolean/fs.fsproj
new file mode 100644
index 00000000000..7392fea781b
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToBoolean/fs.fsproj
@@ -0,0 +1,12 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToBoolean/objectifp.fs b/snippets/fsharp/System/Convert/ToBoolean/objectifp.fs
new file mode 100644
index 00000000000..e5544641aca
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToBoolean/objectifp.fs
@@ -0,0 +1,323 @@
+//
+open System
+open System.Collections
+
+// Define the types of averaging available in the class
+// implementing IConvertible.
+type AverageType =
+ | None = 0s
+ | GeometricMean = 1s
+ | ArithmeticMean = 2s
+ | Median = 3s
+
+// Pass an instance of this class to methods that require an
+// IFormatProvider. The class instance determines the type of
+// average to calculate.
+[]
+type AverageInfo(avgType: AverageType) =
+ // Use this property to set or get the type of averaging.
+ member val TypeOfAverage = avgType with get, set
+
+ interface IFormatProvider with
+ // This method returns a reference to the containing object
+ // if an object of AverageInfo type is requested.
+ member this.GetFormat(argType: Type) =
+ if argType = typeof then
+ this
+ else
+ null
+
+// This class encapsulates an array of double values and implements
+// the IConvertible interface. Most of the IConvertible methods
+// an average of the array elements in one of three types:
+// arithmetic mean, geometric mean, or median.
+type DataSet([] values: double[]) =
+ let data = ResizeArray values
+ let defaultProvider =
+ AverageInfo AverageType.ArithmeticMean
+
+ // Add additional values with this method.
+ member _.Add(value: double) =
+ data.Add value
+ data.Count
+
+ // Get, set, and add values with this indexer property.
+ member _.Item
+ with get (index) =
+ if index >= 0 && index < data.Count then
+ data[index]
+ else
+ raise (InvalidOperationException "[DataSet.get] Index out of range.")
+ and set index value =
+ if index >= 0 && index < data.Count then
+ data[index] <- value
+ elif index = data.Count then
+ data.Add value
+ else
+ raise (InvalidOperationException "[DataSet.set] Index out of range.")
+
+ // This property returns the number of elements in the object.
+ member _.Count =
+ data.Count
+
+ // This method calculates the average of the object's elements.
+ member _.Average(avgType: AverageType) =
+ if data.Count = 0 then
+ 0.0
+ else
+ match avgType with
+ | AverageType.GeometricMean ->
+ let sumProd =
+ Seq.reduce ( * ) data
+
+ // This calculation will not fail with negative
+ // elements.
+ (sign sumProd |> float) * Math.Pow(abs sumProd, 1.0 / (float data.Count))
+
+ | AverageType.ArithmeticMean ->
+ Seq.average data
+
+ | AverageType.Median ->
+ if data.Count % 2 = 0 then
+ (data[data.Count / 2] + data[data.Count / 2 - 1]) / 2.0
+ else
+ data[ data.Count / 2]
+ | _ ->
+ 0.0
+
+ // Get the AverageInfo object from the caller's format provider,
+ // or use the local default.
+ member _.GetAverageInfo(provider: IFormatProvider) =
+ let avgInfo =
+ if provider <> null then
+ provider.GetFormat typeof :?> AverageInfo
+ else
+ null
+
+ if avgInfo = null then
+ defaultProvider
+ else
+ avgInfo
+
+ // Calculate the average and limit the range.
+ member this.CalcNLimitAverage(min: double, max: double, provider: IFormatProvider) =
+ // Get the format provider and calculate the average.
+ let avgInfo = this.GetAverageInfo provider
+ let avg = this.Average avgInfo.TypeOfAverage
+
+ // Limit the range, based on the minimum and maximum values
+ // for the type.
+ if avg > max then max elif avg < min then min else avg
+
+ // The following elements are required by IConvertible.
+ interface IConvertible with
+ // None of these conversion functions throw exceptions. When
+ // the data is out of range for the type, the appropriate
+ // MinValue or MaxValue is used.
+ member _.GetTypeCode() =
+ TypeCode.Object
+
+ member this.ToBoolean(provider: IFormatProvider) =
+ // ToBoolean is false if the dataset is empty.
+ if data.Count <= 0 then
+ false
+
+ // For median averaging, ToBoolean is true if any
+ // non-discarded elements are nonzero.
+ elif AverageType.Median = this.GetAverageInfo(provider).TypeOfAverage then
+ if data.Count % 2 = 0 then
+ (data[data.Count / 2] <> 0.0 || data[data.Count / 2 - 1] <> 0.0)
+ else
+ data[data.Count / 2] <> 0.0
+
+ // For arithmetic or geometric mean averaging, ToBoolean is
+ // true if any element of the dataset is nonzero.
+ else
+ Seq.exists (fun x -> x <> 0.0) data
+
+ member this.ToByte(provider: IFormatProvider) =
+ Convert.ToByte(this.CalcNLimitAverage(float Byte.MinValue, float Byte.MaxValue, provider) )
+
+ member this.ToChar(provider: IFormatProvider) =
+ Convert.ToChar(Convert.ToUInt16(this.CalcNLimitAverage(float Char.MinValue, float Char.MaxValue, provider) ) )
+
+ // Convert to DateTime by adding the calculated average as
+ // seconds to the current date and time. A valid DateTime is
+ // always returned.
+ member this.ToDateTime(provider: IFormatProvider) =
+ let seconds = this.Average(this.GetAverageInfo(provider).TypeOfAverage)
+ try
+ DateTime.Now.AddSeconds seconds
+ with :? ArgumentOutOfRangeException ->
+ if seconds < 0.0 then DateTime.MinValue else DateTime.MaxValue
+
+ member this.ToDecimal(provider: IFormatProvider) =
+ // The Double conversion rounds Decimal.MinValue and
+ // Decimal.MaxValue to invalid Decimal values, so the
+ // following limits must be used.
+ Convert.ToDecimal(this.CalcNLimitAverage(-79228162514264330000000000000.0, 79228162514264330000000000000.0, provider) )
+
+ member this.ToDouble(provider: IFormatProvider) =
+ this.Average(this.GetAverageInfo(provider).TypeOfAverage)
+
+ member this.ToInt16(provider: IFormatProvider) =
+ Convert.ToInt16(this.CalcNLimitAverage(float Int16.MinValue, float Int16.MaxValue, provider) )
+
+ member this.ToInt32(provider: IFormatProvider) =
+ Convert.ToInt32(this.CalcNLimitAverage(Int32.MinValue, Int32.MaxValue, provider) )
+
+ member this.ToInt64(provider: IFormatProvider) =
+ // The Double conversion rounds Int64.MinValue and
+ // Int64.MaxValue to invalid Int64 values, so the following
+ // limits must be used.
+ Convert.ToInt64(this.CalcNLimitAverage(-9223372036854775000., 9223372036854775000., provider) )
+
+ member this.ToSByte(provider: IFormatProvider) =
+ Convert.ToSByte(this.CalcNLimitAverage(float SByte.MinValue, float SByte.MaxValue, provider) )
+
+ member this.ToSingle(provider: IFormatProvider) =
+ Convert.ToSingle(this.CalcNLimitAverage(float Single.MinValue, float Single.MaxValue, provider) )
+
+ member this.ToUInt16(provider: IFormatProvider) =
+ Convert.ToUInt16(this.CalcNLimitAverage(float UInt16.MinValue, float UInt16.MaxValue, provider) )
+
+ member this.ToUInt32(provider: IFormatProvider) =
+ Convert.ToUInt32(this.CalcNLimitAverage(float UInt32.MinValue, float UInt32.MaxValue, provider) )
+
+ member this.ToUInt64(provider: IFormatProvider) =
+ // The Double conversion rounds UInt64.MaxValue to an invalid
+ // UInt64 value, so the following limit must be used.
+ Convert.ToUInt64(this.CalcNLimitAverage(0, 18446744073709550000.0, provider) )
+
+ member this.ToType(conversionType: Type, provider: IFormatProvider) =
+ Convert.ChangeType(this.Average(this.GetAverageInfo(provider).TypeOfAverage), conversionType)
+
+ member this.ToString(provider: IFormatProvider) =
+ let avgType = this.GetAverageInfo(provider).TypeOfAverage
+ $"( {avgType}: {this.Average avgType:G10} )"
+
+// Display a DataSet with three different format providers.
+let displayDataSet (ds: DataSet) =
+ let fmt obj1 obj2 obj3 obj4 = printfn $"{obj1,-12}{obj2,20}{obj3,20}{obj4,20}"
+ let median = AverageInfo AverageType.Median
+ let geMean =
+ AverageInfo AverageType.GeometricMean
+
+ // Display the dataset elements.
+ if ds.Count > 0 then
+ printf $"\nDataSet: [{ds[0]}"
+ for i = 1 to ds.Count - 1 do
+ printf $", {ds[i]}"
+ printfn "]\n"
+
+ fmt "Convert." "Default" "Geometric Mean" "Median"
+ fmt "--------" "-------" "--------------" "------"
+ fmt "ToBoolean"
+ (Convert.ToBoolean(ds, null))
+ (Convert.ToBoolean(ds, geMean))
+ (Convert.ToBoolean(ds, median))
+ fmt "ToByte"
+ (Convert.ToByte(ds, null))
+ (Convert.ToByte(ds, geMean))
+ (Convert.ToByte(ds, median))
+ fmt "ToChar"
+ (Convert.ToChar(ds, null))
+ (Convert.ToChar(ds, geMean))
+ (Convert.ToChar(ds, median))
+ printfn $"""{"ToDateTime",-12}{Convert.ToDateTime(ds, null).ToString "20:yyyy-MM-dd HH:mm:ss"}{Convert.ToDateTime(ds, geMean).ToString "20:yyyy-MM-dd HH:mm:ss"}{Convert.ToDateTime(ds, median).ToString "20:yyyy-MM-dd HH:mm:ss"}"""
+
+ fmt "ToDecimal"
+ (Convert.ToDecimal(ds, null))
+ (Convert.ToDecimal(ds, geMean))
+ (Convert.ToDecimal(ds, median))
+ fmt "ToDouble"
+ (Convert.ToDouble(ds, null))
+ (Convert.ToDouble(ds, geMean))
+ (Convert.ToDouble(ds, median))
+ fmt "ToInt16"
+ (Convert.ToInt16(ds, null))
+ (Convert.ToInt16(ds, geMean))
+ (Convert.ToInt16(ds, median))
+ fmt "ToInt32"
+ (Convert.ToInt32(ds, null))
+ (Convert.ToInt32(ds, geMean))
+ (Convert.ToInt32(ds, median))
+ fmt "ToInt64"
+ (Convert.ToInt64(ds, null))
+ (Convert.ToInt64(ds, geMean))
+ (Convert.ToInt64(ds, median))
+ fmt "ToSByte"
+ (Convert.ToSByte(ds, null))
+ (Convert.ToSByte(ds, geMean))
+ (Convert.ToSByte(ds, median))
+ fmt "ToSingle"
+ (Convert.ToSingle(ds, null))
+ (Convert.ToSingle(ds, geMean))
+ (Convert.ToSingle(ds, median))
+ fmt "ToUInt16"
+ (Convert.ToUInt16(ds, null))
+ (Convert.ToUInt16(ds, geMean))
+ (Convert.ToUInt16(ds, median))
+ fmt "ToUInt32"
+ (Convert.ToUInt32(ds, null))
+ (Convert.ToUInt32(ds, geMean))
+ (Convert.ToUInt32(ds, median))
+ fmt "ToUInt64"
+ (Convert.ToUInt64(ds, null))
+ (Convert.ToUInt64(ds, geMean))
+ (Convert.ToUInt64(ds, median))
+
+printfn
+ """This example of the Convert.To( object, IFormatprovider) methods
+generates the following output. The example displays the values
+returned by the methods, using several IFormatProvider objects.
+"""
+
+let ds1 = DataSet(10.5, 22.2, 45.9, 88.7, 156.05, 297.6)
+displayDataSet ds1
+
+let ds2 = DataSet(359999.95, 425000, 499999.5, 775000, 1695000)
+displayDataSet ds2
+
+// This example of the Convert.To( object, IFormatprovider) methods
+// generates the following output. The example displays the values
+// returned by the methods, using several IFormatProvider objects.
+//
+// DataSet: [10.5, 22.2, 45.9, 88.7, 156.05, 297.6]
+//
+// Convert. Default Geometric Mean Median
+// -------- ------- -------------- ------
+// ToBoolean True True True
+// ToByte 103 59 67
+// ToChar g ; C
+// ToDateTime 2003-05-13 15:04:12 2003-05-13 15:03:28 2003-05-13 15:03:35
+// ToDecimal 103.491666666667 59.4332135445164 67.3
+// ToDouble 103.491666666667 59.4332135445164 67.3
+// ToInt16 103 59 67
+// ToInt32 103 59 67
+// ToInt64 103 59 67
+// ToSByte 103 59 67
+// ToSingle 103.4917 59.43321 67.3
+// ToUInt16 103 59 67
+// ToUInt32 103 59 67
+// ToUInt64 103 59 67
+//
+// DataSet: [359999.95, 425000, 499999.5, 775000, 1695000]
+//
+// Convert. Default Geometric Mean Median
+// -------- ------- -------------- ------
+// ToBoolean True True True
+// ToByte 255 255 255
+// ToChar ? ? ?
+// ToDateTime 2003-05-22 07:39:08 2003-05-20 22:28:45 2003-05-19 09:55:48
+// ToDecimal 750999.89 631577.237188435 499999.5
+// ToDouble 750999.89 631577.237188435 499999.5
+// ToInt16 32767 32767 32767
+// ToInt32 751000 631577 500000
+// ToInt64 751000 631577 500000
+// ToSByte 127 127 127
+// ToSingle 750999.9 631577.3 499999.5
+// ToUInt16 65535 65535 65535
+// ToUInt32 751000 631577 500000
+// ToUInt64 751000 631577 500000
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToBoolean/system.convert snippet.fs b/snippets/fsharp/System/Convert/ToBoolean/system.convert snippet.fs
new file mode 100644
index 00000000000..df4071d59c8
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToBoolean/system.convert snippet.fs
@@ -0,0 +1,313 @@
+module Convert_snippet
+
+open System
+
+//
+let convertDoubleBool (doubleVal: float) =
+ // Double to bool conversion cannot overflow.
+ let boolVal = Convert.ToBoolean doubleVal
+ printfn $"{doubleVal} as a Boolean is: {boolVal}."
+
+ // bool to double conversion cannot overflow.
+ let doubleVal = Convert.ToDouble boolVal
+ printfn $"{boolVal} as a double is: {doubleVal}."
+//
+
+//
+let convertDoubleByte (doubleVal: float) =
+ // Double to byte conversion can overflow.
+ try
+ let byteVal = Convert.ToByte doubleVal
+ printfn $"{doubleVal} as a byte is: {byteVal}."
+
+ // Byte to double conversion cannot overflow.
+ let doubleVal = Convert.ToDouble byteVal
+ printfn $"{byteVal} as a double is: {doubleVal}."
+ with :? OverflowException ->
+ printfn "Overflow in double-to-byte conversion."
+
+//
+
+//
+let convertDoubleInt (doubleVal: float) =
+ let intVal = 0
+ // Double to int conversion can overflow.
+ try
+ let intVal = Convert.ToInt32 doubleVal
+ printfn $"{doubleVal} as an int is: {intVal}"
+ with :? OverflowException ->
+ printfn "Overflow in double-to-int conversion."
+
+ // Int to double conversion cannot overflow.
+ let doubleVal = Convert.ToDouble intVal
+ printfn $"{intVal} as a double is: {doubleVal}"
+//
+
+//
+let convertDoubleDecimal (decimalVal: float) =
+ // Decimal to double conversion cannot overflow.
+ let doubleVal =
+ Convert.ToDouble decimalVal
+ printfn $"{decimalVal} as a double is: {doubleVal}"
+
+ // Conversion from double to decimal can overflow.
+ try
+ let decimalVal = Convert.ToDecimal doubleVal
+ printfn $"{doubleVal} as a decimal is: {decimalVal}"
+ with :? OverflowException ->
+ printfn "Overflow in double-to-double conversion."
+//
+
+//
+let covertDoubleFloat (doubleVal: float) =
+ // Double to float conversion cannot overflow.
+ let floatVal = Convert.ToSingle doubleVal
+ printfn $"{doubleVal} as a float is {floatVal}"
+
+ // Conversion from float to double cannot overflow.
+ let doubleVal = Convert.ToDouble floatVal
+ printfn $"{floatVal} as a double is: {doubleVal}"
+//
+
+//
+let convertDoubleString (doubleVal: float) =
+ // A conversion from Double to string cannot overflow.
+ let stringVal = Convert.ToString doubleVal
+ printfn $"{doubleVal} as a string is: {stringVal}"
+
+ try
+ let doubleVal = Convert.ToDouble stringVal
+ printfn $"{stringVal} as a double is: {doubleVal}"
+ with
+ | :? OverflowException ->
+ printfn "Conversion from string-to-double overflowed."
+ | :? FormatException ->
+ printfn "The string was not formatted as a double."
+ | :? ArgumentException ->
+ printfn "The string pointed to null."
+//
+
+//
+let convertLongChar (longVal: int64) =
+ let charVal = 'a'
+
+ try
+ let charVal = Convert.ToChar longVal
+ printfn $"{longVal} as a char is {charVal}"
+ with :? OverflowException ->
+ printfn "Overflow in long-to-char conversion."
+
+ // A conversion from Char to long cannot overflow.
+ let longVal = Convert.ToInt64 charVal
+ printfn $"{charVal} as an Int64 is {longVal}"
+//
+
+//
+let convertLongByte (longVal: int64) =
+ let byteVal = 0
+
+ // A conversion from Long to byte can overflow.
+ try
+ let byteVal = Convert.ToByte longVal
+ printfn $"{longVal} as a byte is {byteVal}"
+ with :? OverflowException ->
+ printfn "Overflow in long-to-byte conversion."
+
+ // A conversion from Byte to long cannot overflow.
+ let longVal = Convert.ToInt64 byteVal
+ printfn $"{byteVal} as an Int64 is {longVal}"
+//
+
+//
+let convertLongDecimal (longVal: int64) =
+ // Long to decimal conversion cannot overflow.
+ let decimalVal = Convert.ToDecimal longVal
+ printfn $"{longVal} as a decimal is {decimalVal}"
+
+ // Decimal to long conversion can overflow.
+ try
+ let longVal = Convert.ToInt64 decimalVal
+ printfn $"{decimalVal} as a long is {longVal}"
+ with :? OverflowException ->
+ printfn "Overflow in decimal-to-long conversion."
+//
+
+//
+let convertLongFloat (longVal: int64) =
+ // A conversion from Long to float cannot overflow.
+ let floatVal = Convert.ToSingle longVal
+ printfn $"{longVal} as a float is {floatVal}"
+
+ // A conversion from float to long can overflow.
+ try
+ let longVal = Convert.ToInt64 floatVal
+ printfn $"{floatVal} as a long is {longVal}"
+ with :? OverflowException ->
+ printfn "Overflow in float-to-long conversion."
+//
+
+//
+let convertStringBoolean (stringVal: string) =
+ let boolVal = false
+
+ try
+ let boolVal = Convert.ToBoolean stringVal
+ if boolVal then
+ printfn "String was equal to System.Boolean.TrueString."
+ else
+ printfn "String was equal to System.Boolean.FalseString."
+ with :? FormatException ->
+ printfn "The string must equal System.Boolean.TrueString or System.Boolean.FalseString."
+
+ // A conversion from bool to string will always succeed.
+ let stringVal = Convert.ToString boolVal
+ printfn $"{boolVal} as a string is {stringVal}"
+//
+
+//
+let convertStringByte (stringVal: string) =
+ let byteVal = 0
+
+ try
+ let byteVal = Convert.ToByte stringVal
+ printfn $"{stringVal} as a byte is: {byteVal}"
+ with
+ | :? OverflowException ->
+ printfn "Conversion from string to byte overflowed."
+ | :? FormatException ->
+ printfn "The string is not formatted as a byte."
+ | :? ArgumentNullException ->
+ printfn "The string is null."
+
+ //The conversion from byte to string is always valid.
+ let stringVal = Convert.ToString byteVal
+ printfn $"{byteVal} as a string is {stringVal}"
+//
+
+//
+let convertStringChar (stringVal: string) =
+ let charVal = 'a'
+
+ // A string must be one character long to convert to char.
+ try
+ let charVal = Convert.ToChar stringVal
+ printfn $"{stringVal} as a char is {charVal}"
+ with
+ | :? FormatException ->
+ printfn "The string is longer than one character."
+ | :? ArgumentNullException ->
+ printfn "The string is null."
+
+ // A char to string conversion will always succeed.
+ let stringVal = Convert.ToString charVal
+ printfn $"The character as a string is {stringVal}"
+//
+
+//
+let convertStringDecimal (stringVal: string) =
+ let decimalVal = 0m
+
+ try
+ let decimalVal = Convert.ToDecimal(stringVal)
+ printfn $"The string as a decimal is {decimalVal}."
+ with
+ | :? OverflowException ->
+ printfn "The conversion from string to decimal overflowed."
+ | :? FormatException ->
+ printfn "The string is not formatted as a decimal."
+ | :? ArgumentNullException ->
+ printfn "The string is null."
+
+ // Decimal to string conversion will not overflow.
+ let stringVal = Convert.ToString decimalVal
+ printfn $"The decimal as a string is {stringVal}."
+//
+
+//
+let convertStringFloat (stringVal: string) =
+ let floatVal = 0f
+
+ try
+ let floatVal = Convert.ToSingle stringVal
+ printfn $"The string as a float is {floatVal}."
+ with
+ | :? OverflowException ->
+ printfn "The conversion from string-to-float overflowed."
+ | :? FormatException ->
+ printfn "The string is not formatted as a float."
+ | :? ArgumentNullException ->
+ printfn "The string is null."
+
+ // Float to string conversion will not overflow.
+ let stringVal = Convert.ToString floatVal
+ printfn $"The float as a string is {stringVal}."
+//
+
+//
+let convertCharDecimal (charVal: char) =
+ let decimalVal = 0m
+
+ // Char to decimal conversion is not supported and will always
+ // throw an InvalidCastException.
+ try
+ let decimalVal = Convert.ToDecimal charVal
+ ()
+ with :? InvalidCastException ->
+ printfn "Char-to-Decimal conversion is not supported by the .NET Runtime."
+
+ //Decimal to char conversion is also not supported.
+ try
+ let charVal = Convert.ToChar decimalVal
+ ()
+ with :? InvalidCastException ->
+ printfn "Decimal-to-Char conversion is not supported by the .NET Runtime."
+//
+
+//
+let convertByteDecimal (byteVal: byte) =
+ // Byte to decimal conversion will not overflow.
+ let decimalVal = Convert.ToDecimal byteVal
+ printfn $"The byte as a decimal is {decimalVal}."
+
+ // Decimal to byte conversion can overflow.
+ try
+ let byteVal = Convert.ToByte decimalVal
+ printfn $"The Decimal as a byte is {byteVal}."
+ with :? OverflowException ->
+ printfn "The decimal value is too large for a byte."
+//
+
+//
+let convertByteSingle (byteVal: byte) =
+ // Byte to float conversion will not overflow.
+ let floatVal = Convert.ToSingle byteVal
+ printfn $"The byte as a float is {floatVal}."
+
+ // Float to byte conversion can overflow.
+ try
+ let byteVal = Convert.ToByte floatVal
+ printfn $"The float as a byte is {byteVal}."
+ with :? OverflowException ->
+ printfn "The float value is too large for a byte."
+//
+
+//
+let convertBoolean () =
+ let year = 1979
+ let month = 7
+ let day = 28
+ let hour = 13
+ let minute = 26
+ let second = 15
+ let millisecond = 53
+
+ let dateTime = DateTime(year, month, day, hour, minute, second, millisecond)
+
+ // System.InvalidCastException is always thrown.
+ try
+ let boolVal = Convert.ToBoolean dateTime
+ ()
+ with :? InvalidCastException ->
+ printfn "Conversion from DateTime to Boolean is not supported by the .NET Runtime."
+//
+
diff --git a/snippets/fsharp/System/Convert/ToBoolean/toboolean2.fs b/snippets/fsharp/System/Convert/ToBoolean/toboolean2.fs
new file mode 100644
index 00000000000..d2db79d3de7
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToBoolean/toboolean2.fs
@@ -0,0 +1,228 @@
+module toboolean2
+
+open System
+
+let convertByte () =
+ //
+ let bytes = [| Byte.MinValue; 100uy; 200uy; Byte.MaxValue |]
+
+ for byteValue in bytes do
+ let result = Convert.ToBoolean byteValue
+ printfn $"{byteValue,-5} --> {result}"
+ // The example displays the following output:
+ // 0 --> False
+ // 100 --> True
+ // 200 --> True
+ // 255 --> True
+ //
+
+let convertDecimal () =
+ //
+ let numbers =
+ [| Decimal.MinValue; -12034.87m; -100m; 0m
+ 300m; 6790823.45m; Decimal.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToBoolean number
+ printfn $"{number,-30} --> {result}"
+ // The example displays the following output:
+ // -79228162514264337593543950335 --> True
+ // -12034.87 --> True
+ // -100 --> True
+ // 0 --> False
+ // 300 --> True
+ // 6790823.45 --> True
+ // 79228162514264337593543950335 --> True
+ //
+
+let convertInt16 () =
+ //
+ let numbers =
+ [| Int16.MinValue; -10000s; -154s; 0s
+ 216s; 21453s; Int16.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToBoolean number
+ printfn $"{number,-7:N0} --> {result}"
+ // The example displays the following output:
+ // -32,768 --> True
+ // -10,000 --> True
+ // -154 --> True
+ // 0 --> False
+ // 216 --> True
+ // 21,453 --> True
+ // 32,767 --> True
+ //
+
+let convertInt32 () =
+ //
+ let numbers =
+ [| Int32.MinValue; -201649; -68; 0
+ 612; 4038907; Int32.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToBoolean number
+ printfn $"{number,-15:N0} --> {result}"
+ // The example displays the following output:
+ // -2,147,483,648 --> True
+ // -201,649 --> True
+ // -68 --> True
+ // 0 --> False
+ // 612 --> True
+ // 4,038,907 --> True
+ // 2,147,483,647 --> True
+ //
+
+let convertInt64 () =
+ //
+ let numbers =
+ [| Int64.MinValue; -2016493; -689
+ 0; 6121; 403890774; Int64.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToBoolean number
+ printfn $"{number,-26:N0} --> {result}"
+ // The example displays the following output:
+ // -9,223,372,036,854,775,808 --> True
+ // -2,016,493 --> True
+ // -689 --> True
+ // 0 --> False
+ // 6,121 --> True
+ // 403,890,774 --> True
+ // 9,223,372,036,854,775,807 --> True
+ //
+
+let convertSByte () =
+ //
+ let numbers =
+ [| SByte.MinValue; -1y; 0y
+ 10y; 100y; SByte.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToBoolean number
+ printfn $"{number,-5} --> {result}"
+ // The example displays the following output:
+ // -128 --> True
+ // -1 --> True
+ // 0 --> False
+ // 10 --> True
+ // 100 --> True
+ // 127 --> True
+ //
+
+let convertSingle () =
+ //
+ let numbers =
+ [| Single.MinValue; -193.0012f; 20e-15f; 0f
+ 10551e-10f; 100.3398f; Single.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToBoolean number
+ printfn $"{number,-15} --> {result}"
+ // The example displays the following output:
+ // -3.402823E+38 --> True
+ // -193.0012 --> True
+ // 2E-14 --> True
+ // 0 --> False
+ // 1.0551E-06 --> True
+ // 100.3398 --> True
+ // 3.402823E+38 --> True
+ //
+
+let convertUInt16 () =
+ //
+ let numbers =
+ [| UInt16.MinValue; 216us; 21453us; UInt16.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToBoolean number
+ printfn $"{number,-7:N0} --> {result}"
+ // The example displays the following output:
+ // 0 --> False
+ // 216 --> True
+ // 21,453 --> True
+ // 65,535 --> True
+ //
+
+let convertUInt32 () =
+ //
+ let numbers =
+ [| UInt32.MinValue; 612u; 4038907u; uint Int32.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToBoolean number
+ printfn $"{number,-15:N0} --> {result}"
+ // The example displays the following output:
+ // 0 --> False
+ // 612 --> True
+ // 4,038,907 --> True
+ // 2,147,483,647 --> True
+ //
+
+let convertUInt64 () =
+ //
+ let numbers =
+ [| UInt64.MinValue; 6121uL; 403890774uL; UInt64.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToBoolean number
+ printfn $"{number,-26:N0} --> {result}"
+ // The example displays the following output:
+ // 0 --> False
+ // 6,121 --> True
+ // 403,890,774 --> True
+ // 18,446,744,073,709,551,615 --> True
+ //
+
+let convertObject () =
+ //
+ let objects: obj[] =
+ [| 16.33; -24; 0; "12"; "12.7"; String.Empty
+ "1String"; "True"; "false"; null
+ System.Collections.ArrayList() |]
+
+ for obj in objects do
+ printf $"""{(if obj <> null then $"{obj} ({obj.GetType().Name})" else "null"),-40} --> """
+ try
+ Console.WriteLine("{0}", Convert.ToBoolean(obj))
+ with
+ | :? FormatException ->
+ printfn "Bad Format"
+ | :? InvalidCastException ->
+ printfn "No Conversion"
+ // The example displays the following output:
+ // 16.33 (Double) --> True
+ // -24 (Int32) --> True
+ // 0 (Int32) --> False
+ // 12 (String) --> Bad Format
+ // 12.7 (String) --> Bad Format
+ // (String) --> Bad Format
+ // 1String (String) --> Bad Format
+ // True (String) --> True
+ // false (String) --> False
+ // null --> False
+ // System.Collections.ArrayList (ArrayList) --> No Conversion
+ //
+
+
+convertByte ()
+printfn "-----"
+convertDecimal ()
+printfn "-----"
+convertInt16 ()
+printfn "-----"
+convertInt32 ()
+printfn "-----"
+convertInt64 ()
+printfn "-----"
+convertSByte ()
+printfn "-----"
+convertSingle ()
+printfn "-----"
+convertUInt16 ()
+printfn "-----"
+convertUInt32 ()
+printfn "-----"
+convertUInt64 ()
+printfn "-----"
+convertObject ()
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToByte/Conversion.fs b/snippets/fsharp/System/Convert/ToByte/Conversion.fs
new file mode 100644
index 00000000000..a1e17820116
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToByte/Conversion.fs
@@ -0,0 +1,274 @@
+open System
+
+
+let convertHexToNegativeInteger () =
+ //
+ // Create a hexadecimal value out of range of the Integer type.
+ let value = Convert.ToString(int64 Int32.MaxValue + 1L, 16)
+ // Convert it back to a number.
+ try
+ let number = Convert.ToInt32(value, 16)
+ printfn $"0x{value} converts to {number}."
+ with :? OverflowException ->
+ printfn $"Unable to convert '0x{value}' to an integer."
+ //
+
+let convertHexToInteger () =
+ //
+ // Create a hexadecimal value out of range of the Integer type.
+ let sourceNumber = int64 Int32.MaxValue + 1L
+ let isNegative = sign sourceNumber = -1
+ let value = Convert.ToString(sourceNumber, 16)
+ try
+ let targetNumber = Convert.ToInt32(value, 16)
+ if not isNegative && targetNumber &&& 0x80000000 <> 0 then
+ raise (OverflowException())
+ else
+ printfn $"0x{value} converts to {targetNumber}."
+ with :? OverflowException ->
+ printfn $"Unable to convert '0x{value}' to an integer."
+ // Displays the following to the console:
+ // Unable to convert '0x80000000' to an integer.
+ //
+
+let convertNegativeHexToByte () =
+ //
+ // Create a hexadecimal value out of range of the Byte type.
+ let value = SByte.MinValue.ToString "X"
+ // Convert it back to a number.
+ try
+ let number = Convert.ToByte(value, 16)
+ printfn $"0x{value} converts to {number}."
+ with :? OverflowException ->
+ printfn $"Unable to convert '0x{value}' to a byte."
+ //
+
+let convertHexToByte () =
+ //
+ // Create a negative hexadecimal value out of range of the Byte type.
+ let sourceNumber = SByte.MinValue
+ let isSigned = sign (sourceNumber.GetType().GetField("MinValue").GetValue null :?> int8) = -1
+ let value = sourceNumber.ToString "X"
+ try
+ let targetNumber = Convert.ToByte(value, 16)
+ if isSigned && targetNumber &&& 0x80uy <> 0uy then
+ raise (OverflowException())
+ else
+ printfn $"0x{value} converts to {targetNumber}."
+ with :? OverflowException ->
+ printfn $"Unable to convert '0x{value}' to an unsigned byte."
+ // Displays the following to the console:
+ // Unable to convert '0x80' to an unsigned byte.
+ //
+
+let convertHexToNegativeShort () =
+ //
+ // Create a hexadecimal value out of range of the Int16 type.
+ let value = Convert.ToString(int Int16.MaxValue + 1, 16)
+ // Convert it back to a number.
+ try
+ let number = Convert.ToInt16(value, 16)
+ printfn $"0x{value} converts to {number}."
+ with :? OverflowException ->
+ printfn $"Unable to convert '0x{value}' to a 16-bit integer."
+ //
+
+let convertHexToShort () =
+ //
+ // Create a hexadecimal value out of range of the Short type.
+ let sourceNumber = int Int16.MaxValue + 1
+ let isNegative = sign sourceNumber = -1
+ let value = Convert.ToString(sourceNumber, 16)
+ try
+ let targetNumber = Convert.ToInt16(value, 16)
+ if not isNegative && targetNumber &&& 0x8000s <> 0s then
+ raise (OverflowException())
+ else
+ printfn $"0x{value} converts to {targetNumber}."
+ with :? OverflowException ->
+ printfn $"Unable to convert '0x{value}' to a 16-bit integer."
+ // Displays the following to the console:
+ // Unable to convert '0x8000' to a 16-bit integer.
+ //
+
+let convertHexToNegativeLong () =
+ //
+ // Create a hexadecimal value out of range of the long type.
+ let value = UInt64.MaxValue.ToString "X"
+ // Use Convert.ToInt64 to convert it back to a number.
+ try
+ let number = Convert.ToInt64(value, 16)
+ printfn $"0x{value} converts to {number}."
+ with :? OverflowException ->
+ printfn $"Unable to convert '0x{value}' to a long integer."
+ //
+
+let convertHexToLong () =
+ //
+ // Create a negative hexadecimal value out of range of the Byte type.
+ let sourceNumber = UInt64.MaxValue
+ let isSigned = sign (Convert.ToDouble(sourceNumber.GetType().GetField("MinValue").GetValue null)) = -1
+ let value = sourceNumber.ToString "X"
+ try
+ let targetNumber = Convert.ToInt64(value, 16)
+ if not isSigned && targetNumber &&& 0x80000000L <> 0L then
+ raise (OverflowException())
+ else
+ printfn $"0x{value} converts to {targetNumber}."
+ with :? OverflowException ->
+ printfn $"Unable to convert '0x{value}' to a long integer."
+ // Displays the following to the console:
+ // Unable to convert '0xFFFFFFFFFFFFFFFF' to a long integer.
+ //
+
+let convertHexToNegativeSByte () =
+ //
+ // Create a hexadecimal value out of range of the SByte type.
+ let value = Convert.ToString(Byte.MaxValue, 16)
+ // Convert it back to a number.
+ try
+ let number = Convert.ToSByte(value, 16)
+ printfn $"0x{value} converts to {number}."
+ with :? OverflowException ->
+ printfn $"Unable to convert '0x{value}' to a signed byte."
+ //
+
+let convertHexToSByte () =
+ //
+ // Create a hexadecimal value out of range of the SByte type.
+ let sourceNumber = Byte.MaxValue
+ let isSigned = sign (Convert.ToDouble(sourceNumber.GetType().GetField("MinValue").GetValue null)) = -1
+ let value = Convert.ToString(sourceNumber, 16)
+ try
+ let targetNumber = Convert.ToSByte(value, 16)
+ if not isSigned && targetNumber &&& 0x80y <> 0y then
+ raise (OverflowException())
+ else
+ printfn $"0x{value} converts to {targetNumber}."
+ with :? OverflowException ->
+ printfn $"Unable to convert '0x{value}' to a signed byte."
+ // Displays the following to the console:
+ // Unable to convert '0xff' to a signed byte.
+ //
+
+let convertNegativeHexToUInt16 () =
+ //
+ // Create a hexadecimal value out of range of the UInt16 type.
+ let value = Convert.ToString(Int16.MinValue, 16)
+ // Convert it back to a number.
+ try
+ let number = Convert.ToUInt16(value, 16)
+ printfn $"0x{value} converts to {number}."
+ with :? OverflowException ->
+ printfn $"Unable to convert '0x{value}' to an unsigned short integer."
+ //
+
+let convertHexToUInt16 () =
+ //
+ // Create a negative hexadecimal value out of range of the UInt16 type.
+ let sourceNumber = Int16.MinValue
+ let isSigned = sign (sourceNumber.GetType().GetField("MinValue").GetValue null :?> int16) = -1
+ let value = Convert.ToString(sourceNumber, 16)
+ try
+ let targetNumber = Convert.ToUInt16(value, 16)
+ if isSigned && targetNumber &&& 0x8000us <> 0us then
+ raise (OverflowException())
+ else
+ printfn $"0x{value} converts to {targetNumber}."
+ with :? OverflowException ->
+ printfn $"Unable to convert '0x{value}' to an unsigned short integer."
+ // Displays the following to the console:
+ // Unable to convert '0x8000' to an unsigned short integer.
+ //
+
+let convertNegativeHexToUInt32 () =
+ //
+ // Create a hexadecimal value out of range of the UInt32 type.
+ let value = Convert.ToString(Int32.MinValue, 16)
+ // Convert it back to a number.
+ try
+ let number = Convert.ToUInt32(value, 16)
+ printfn $"0x{value} converts to {number}."
+ with :? OverflowException ->
+ printfn $"Unable to convert '0x{value}' to an unsigned integer."
+ //
+
+let convertHexToUInt32 () =
+ //
+ // Create a negative hexadecimal value out of range of the UInt32 type.
+ let sourceNumber = Int32.MinValue
+ let isSigned = sign (sourceNumber.GetType().GetField("MinValue").GetValue null :?> int) = -1
+ let value = Convert.ToString(sourceNumber, 16)
+ try
+ let targetNumber = Convert.ToUInt32(value, 16)
+ if isSigned && targetNumber &&& 0x80000000u <> 0u then
+ raise (OverflowException())
+ else
+ printfn $"0x{value} converts to {targetNumber}."
+ with :? OverflowException ->
+ printfn $"Unable to convert '0x{value}' to an unsigned integer."
+ // Displays the following to the console:
+ // Unable to convert '0x80000000' to an unsigned integer.
+ //
+
+let convertNegativeHexToUInt64 () =
+ //
+ // Create a hexadecimal value out of range of the UInt64 type.
+ let value = Convert.ToString(Int64.MinValue, 16)
+ // Convert it back to a number.
+ try
+ let number = Convert.ToUInt64(value, 16)
+ printfn $"0x{value} converts to {number}."
+ with :? OverflowException ->
+ printfn $"Unable to convert '0x{value}' to an unsigned long integer."
+ //
+
+let convertHexToUInt64 () =
+ //
+ // Create a negative hexadecimal value out of range of the UInt64 type.
+ let sourceNumber = Int64.MinValue
+ let isSigned = sign (sourceNumber.GetType().GetField("MinValue").GetValue null :?> int64) = -1
+ let value = Convert.ToString(sourceNumber, 16)
+ try
+ let targetNumber = Convert.ToUInt64(value, 16)
+ if isSigned && targetNumber &&& 0x8000000000000000uL <> 0uL then
+ raise (OverflowException())
+ else
+ printfn $"0x{value} converts to {targetNumber}."
+ with :? OverflowException ->
+ printfn $"Unable to convert '0x{value}' to an unsigned long integer."
+ // Displays the following to the console:
+ // Unable to convert '0x8000000000000000' to an unsigned long integer.
+ //
+
+convertHexToNegativeInteger ()
+printfn ""
+convertHexToInteger ()
+printfn ""
+convertNegativeHexToByte ()
+printfn ""
+convertHexToByte ()
+printfn ""
+convertHexToNegativeShort ()
+printfn ""
+convertHexToShort ()
+printfn ""
+convertHexToNegativeLong ()
+printfn ""
+convertHexToLong ()
+printfn ""
+convertHexToNegativeSByte ()
+printfn ""
+convertHexToSByte ()
+printfn ""
+convertNegativeHexToUInt16 ()
+printfn ""
+convertHexToUInt16 ()
+printfn ""
+convertNegativeHexToUInt32 ()
+printfn ""
+convertHexToUInt32 ()
+printfn ""
+convertNegativeHexToUInt64 ()
+printfn ""
+convertHexToUInt64 ()
diff --git a/snippets/fsharp/System/Convert/ToByte/fs.fsproj b/snippets/fsharp/System/Convert/ToByte/fs.fsproj
new file mode 100644
index 00000000000..dde23da22f4
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToByte/fs.fsproj
@@ -0,0 +1,9 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToChar/fs.fsproj b/snippets/fsharp/System/Convert/ToChar/fs.fsproj
new file mode 100644
index 00000000000..e298b0c613d
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToChar/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToChar/stringnonnum.fs b/snippets/fsharp/System/Convert/ToChar/stringnonnum.fs
new file mode 100644
index 00000000000..65439c3b52f
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToChar/stringnonnum.fs
@@ -0,0 +1,81 @@
+module stringnonnum
+
+//
+open System
+open System.Globalization
+
+type DummyProvider() =
+ interface IFormatProvider with
+ // Normally, GetFormat returns an object of the requested type
+ // (usually itself) if it is able; otherwise, it returns Nothing.
+ member _.GetFormat(argType: Type) =
+ // Here, GetFormat displays the name of argType, after removing
+ // the namespace information. GetFormat always returns null.
+ let argStr = string argType
+ let argStr = if argStr = "" then "Empty" else argStr
+ let argStr = argStr.Substring(argStr.LastIndexOf '.' + 1)
+
+ printf $"{argStr,-20}"
+ null
+
+// Create an instance of IFormatProvider.
+let provider =
+ { new IFormatProvider with
+ // Normally, GetFormat returns an object of the requested type
+ // (usually itself) if it is able; otherwise, it returns Nothing.
+ member _.GetFormat(argType: Type) =
+ // Here, GetFormat displays the name of argType, after removing
+ // the namespace information. GetFormat always returns null.
+ let argStr = string argType
+ let argStr = if argStr = "" then "Empty" else argStr
+ let argStr = argStr.Substring(argStr.LastIndexOf '.' + 1)
+
+ printf $"{argStr,-20}"
+ null }
+
+let format obj1 obj2 obj3 = printfn $"{obj1,-17}{obj2,-17}{obj3}"
+
+// Convert these values using DummyProvider.
+let Int32A = "-252645135"
+let DoubleA = "61680.3855"
+let DayTimeA = "2001/9/11 13:45"
+
+let BoolA = "True"
+let StringA = "Qwerty"
+let CharA = "$"
+
+printfn
+ """This example of selected Convert.To( String, IFormatProvider )
+methods generates the following output. The example displays the
+provider type if the IFormatProvider is called.
+
+Note: For the ToBoolean, ToString, and ToChar methods, the
+IFormatProvider object is not referenced.
+"""
+
+// The format provider is called for the following conversions.
+format "ToInt32" Int32A (Convert.ToInt32(Int32A, provider) )
+format "ToDouble" DoubleA (Convert.ToDouble(DoubleA, provider) )
+format "ToDateTime" DayTimeA (Convert.ToDateTime(DayTimeA, provider) )
+
+// The format provider is not called for these conversions.
+printfn ""
+format "ToBoolean" BoolA (Convert.ToBoolean(BoolA, provider) )
+format "ToString" StringA (Convert.ToString(StringA, provider) )
+format "ToChar" CharA (Convert.ToChar(CharA, provider) )
+
+// This example of selected Convert.To( String, IFormatProvider )
+// methods generates the following output. The example displays the
+// provider type if the IFormatProvider is called.
+//
+// Note: For the ToBoolean, ToString, and ToChar methods, the
+// IFormatProvider object is not referenced.
+//
+// NumberFormatInfo ToInt32 -252645135 -252645135
+// NumberFormatInfo ToDouble 61680.3855 61680.3855
+// DateTimeFormatInfo ToDateTime 2001/9/11 13:45 9/11/2001 1:45:00 PM
+//
+// ToBoolean True True
+// ToString Qwerty Qwerty
+// ToChar $ $
+//
diff --git a/snippets/fsharp/System/Convert/ToChar/tochar1.fs b/snippets/fsharp/System/Convert/ToChar/tochar1.fs
new file mode 100644
index 00000000000..192a29f5772
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToChar/tochar1.fs
@@ -0,0 +1,221 @@
+module tochar1
+
+open System
+
+let convertByte () =
+ //
+ let bytes =
+ [| Byte.MinValue; 40uy; 80uy; 120uy; 180uy; Byte.MaxValue|]
+ for number in bytes do
+ let result = Convert.ToChar number
+ printfn $"{number} converts to '{result}'."
+ // The example displays the following output:
+ // 0 converts to ' '.
+ // 40 converts to '('.
+ // 80 converts to 'P'.
+ // 120 converts to 'x'.
+ // 180 converts to '''.
+ // 255 converts to 'ÿ'.
+ //
+
+let convertInt16 () =
+ //
+ let numbers =
+ [| Int16.MinValue; 0s; 40s; 160s
+ 255s; 1028s; 2011s; Int16.MaxValue |]
+ for number in numbers do
+ try
+ let result = Convert.ToChar number
+ printfn $"{number} converts to '{result}'."
+ with :? OverflowException ->
+ printfn $"{number} is outside the range of the Char data type."
+ // The example displays the following output:
+ // -32768 is outside the range of the Char data type.
+ // 0 converts to ' '.
+ // 40 converts to '('.
+ // 160 converts to ' '.
+ // 255 converts to 'ÿ'.
+ // 1028 converts to 'Є'.
+ // 2011 converts to 'ߛ'.
+ // 32767 converts to '翿'.
+ //
+
+let convertInt32 () =
+ //
+ let numbers =
+ [| -1; 0; 40; 160; 255; 1028; 2011
+ 30001; 207154; Int32.MaxValue |]
+ for number in numbers do
+ try
+ let result = Convert.ToChar number
+ printfn $"{number} converts to '{result}'."
+ with :? OverflowException ->
+ printfn $"{number} is outside the range of the Char data type."
+ // -1 is outside the range of the Char data type.
+ // 0 converts to ' '.
+ // 40 converts to '('.
+ // 160 converts to ' '.
+ // 255 converts to 'ÿ'.
+ // 1028 converts to 'Є'.
+ // 2011 converts to 'ߛ'.
+ // 30001 converts to '由'.
+ // 207154 is outside the range of the Char data type.
+ // 2147483647 is outside the range of the Char data type.
+ //
+
+let convertSByte () =
+ //
+ let numbers =
+ [| SByte.MinValue; -1y; 40y; 80y; 120y; SByte.MaxValue |]
+ for number in numbers do
+ try
+ let result = Convert.ToChar number
+ printfn $"{number} converts to '{result}'."
+ with :? OverflowException ->
+ printfn $"{number} is outside the range of the Char data type."
+ // The example displays the following output:
+ // -128 is outside the range of the Char data type.
+ // -1 is outside the range of the Char data type.
+ // 40 converts to '('.
+ // 80 converts to 'P'.
+ // 120 converts to 'x'.
+ // 127 converts to '⌂'.
+ //
+
+let convertString () =
+ //
+ let nullString = null
+ let strings = [| "A"; "This"; '\u0007'.ToString(); nullString |]
+ for string in strings do
+ try
+ let result = Convert.ToChar string
+ printfn $"'{string}' converts to '{result}'."
+ with
+ | :? FormatException ->
+ printfn $"'{string}' is not in the correct format for conversion to a Char."
+ | :? ArgumentNullException ->
+ printfn "A null string cannot be converted to a Char."
+ // The example displays the following output:
+ // 'A' converts to 'A'.
+ // 'This' is not in the correct format for conversion to a Char.
+ // ' ' converts to ' '.
+ // A null string cannot be converted to a Char.
+ //
+
+let convertUInt16 () =
+ //
+ let numbers =
+ [| UInt16.MinValue; 40us; 160us; 255us
+ 1028us; 2011us; UInt16.MaxValue |]
+ for number in numbers do
+ let result = Convert.ToChar number
+ printfn $"{number} converts to '{result}'."
+ // The example displays the following output:
+ // 0 converts to ' '.
+ // 40 converts to '('.
+ // 160 converts to ' '.
+ // 255 converts to 'ÿ'.
+ // 1028 converts to 'Є'.
+ // 2011 converts to 'ߛ'.
+ // 65535 converts to ''.
+ //
+
+let convertUInt32 () =
+ //
+ let numbers =
+ [| UInt32.MinValue; 40u; 160u; 255u; 1028u
+ 2011u; 30001u; 207154u; uint Int32.MaxValue |]
+ for number in numbers do
+ try
+ let result = Convert.ToChar number
+ printfn $"{number} converts to '{result}'."
+ with :? OverflowException ->
+ printfn $"{number} is outside the range of the Char data type."
+ // The example displays the following output:
+ // 0 converts to ' '.
+ // 40 converts to '('.
+ // 160 converts to ' '.
+ // 255 converts to 'ÿ'.
+ // 1028 converts to 'Є'.
+ // 2011 converts to 'ߛ'.
+ // 30001 converts to '由'.
+ // 207154 is outside the range of the Char data type.
+ // 2147483647 is outside the range of the Char data type.
+ //
+
+let convertUInt64 () =
+ //
+ let numbers =
+ [| UInt64.MinValue; 40uL; 160uL; 255uL; 1028uL
+ 2011uL; 30001uL; 207154uL; uint64 Int64.MaxValue |]
+ for number in numbers do
+ try
+ let result = Convert.ToChar number
+ printfn $"{number} converts to '{result}'."
+ with :? OverflowException ->
+ printfn $"{number} is outside the range of the Char data type."
+ // The example displays the following output:
+ // 0 converts to ' '.
+ // 40 converts to '('.
+ // 160 converts to ' '.
+ // 255 converts to 'ÿ'.
+ // 1028 converts to 'Є'.
+ // 2011 converts to 'ߛ'.
+ // 30001 converts to '由'.
+ // 207154 is outside the range of the Char data type.
+ // 9223372036854775807 is outside the range of the Char data type.
+ //
+
+let convertObject () =
+ //
+ let values: obj[] =
+ [| 'r'; "s"; "word"; 83uy; 77; 109324; 335812911
+ DateTime(2009, 3, 10); 1934u
+ -17y; 169.34; 175.6m; null |]
+
+ for value in values do
+ try
+ let result = Convert.ToChar(value)
+ printfn $"The {value.GetType().Name} value {value} converts to {result}."
+ with
+ | :? FormatException as e ->
+ printfn $"{e.Message}"
+ | :? InvalidCastException ->
+ printfn $"Conversion of the {value.GetType().Name} value {value} to a Char is not supported."
+ | :? OverflowException ->
+ printfn $"The {value.GetType().Name} value {value} is outside the range of the Char data type."
+ | :? NullReferenceException ->
+ printfn "Cannot convert a null reference to a Char."
+ // The example displays the following output:
+ // The Char value r converts to r.
+ // The String value s converts to s.
+ // String must be exactly one character long.
+ // The Byte value 83 converts to S.
+ // The Int32 value 77 converts to M.
+ // The Int32 value 109324 is outside the range of the Char data type.
+ // The Int32 value 335812911 is outside the range of the Char data type.
+ // Conversion of the DateTime value 3/10/2009 12:00:00 AM to a Char is not supported.
+ // The UInt32 value 1934 converts to ?.
+ // The SByte value -17 is outside the range of the Char data type.
+ // Conversion of the Double value 169.34 to a Char is not supported.
+ // Conversion of the Decimal value 175.6 to a Char is not supported.
+ // Cannot convert a null reference to a Char.
+ //
+
+convertByte ()
+printfn "-----"
+convertInt16 ()
+printfn "-----"
+convertInt32 ()
+printfn "-----"
+convertSByte ()
+printfn "-----"
+convertString ()
+printfn "-----"
+convertUInt16 ()
+printfn "-----"
+convertUInt32 ()
+printfn "-----"
+convertUInt64 ()
+printfn "-----"
+convertObject ()
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToDateTime/ToDateTime1.fs b/snippets/fsharp/System/Convert/ToDateTime/ToDateTime1.fs
new file mode 100644
index 00000000000..ee32d88fd9b
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToDateTime/ToDateTime1.fs
@@ -0,0 +1,50 @@
+module ToDateTime1
+
+//
+open System
+
+let convertToDateTime (value: obj) =
+ try
+ let convertedDate = Convert.ToDateTime value
+ printfn $"'{value}' converts to {convertedDate}."
+ with
+ | :? FormatException ->
+ printfn $"'{value}' is not in the proper format."
+ | :? InvalidCastException ->
+ printfn $"Conversion of the {value.GetType().Name} '{value}' is not supported"
+
+[]
+let main _ =
+ // Try converting an integer.
+ let number = 16352
+ convertToDateTime number
+
+ // Convert a null.
+ let obj = box null
+ convertToDateTime obj
+
+ // Convert a non-date string.
+ let nonDateString = "monthly"
+ convertToDateTime nonDateString
+
+ // Try to convert various date strings.
+ let dateString = "05/01/1996"
+ convertToDateTime dateString
+ let dateString = "Tue Apr 28, 2009"
+ convertToDateTime dateString
+ let dateString = "06 July 2008 7:32:47 AM"
+ convertToDateTime dateString
+ let dateString = "17:32:47.003"
+ convertToDateTime dateString
+
+ 0
+
+// The example displays the following output:
+// Conversion of the Int32 '16352' is not supported
+// '' converts to 1/1/0001 12:00:00 AM.
+// 'monthly' is not in the proper format.
+// '05/01/1996' converts to 5/1/1996 12:00:00 AM.
+// 'Tue Apr 28, 2009' converts to 4/28/2009 12:00:00 AM.
+// '06 July 2008 7:32:47 AM' converts to 7/6/2008 7:32:47 AM.
+// '17:32:47.003' converts to 5/28/2008 5:32:47 PM.
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToDateTime/ToDateTime1/fs.fsproj b/snippets/fsharp/System/Convert/ToDateTime/ToDateTime1/fs.fsproj
new file mode 100644
index 00000000000..1f66a3079ae
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToDateTime/ToDateTime1/fs.fsproj
@@ -0,0 +1,9 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToDateTime/ToDateTime2.fs b/snippets/fsharp/System/Convert/ToDateTime/ToDateTime2.fs
new file mode 100644
index 00000000000..6f749c078fc
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToDateTime/ToDateTime2.fs
@@ -0,0 +1,59 @@
+module ToDateTime2
+
+//
+open System
+
+let convertToDateTime (value: string) =
+ try
+ let convertedDate = Convert.ToDateTime value
+ printfn $"'{value}' converts to {convertedDate} {convertedDate.Kind} time."
+ with :?FormatException ->
+ printfn $"'{value}' is not in the proper format."
+
+[]
+let main _ =
+ let dateString = null
+
+ // Convert a null string.
+ convertToDateTime dateString
+
+ // Convert an empty string.
+ let dateString = String.Empty
+ convertToDateTime dateString
+
+ // Convert a non-date string.
+ let dateString = "not a date"
+ convertToDateTime dateString
+
+ // Try to convert various date strings.
+ let dateString = "05/01/1996"
+ convertToDateTime dateString
+ let dateString = "Tue Apr 28, 2009"
+ convertToDateTime dateString
+ let dateString = "Wed Apr 28, 2009"
+ convertToDateTime dateString
+ let dateString = "06 July 2008 7:32:47 AM"
+ convertToDateTime dateString
+ let dateString = "17:32:47.003"
+ convertToDateTime dateString
+ // Convert a string returned by DateTime.ToString("R").
+ let dateString = "Sat, 10 May 2008 14:32:17 GMT"
+ convertToDateTime dateString
+ // Convert a string returned by DateTime.ToString("o").
+ let dateString = "2009-05-01T07:54:59.9843750-04:00"
+ convertToDateTime dateString
+
+ 0
+
+// The example displays the following output:
+// '' converts to 1/1/0001 12:00:00 AM Unspecified time.
+// '' is not in the proper format.
+// 'not a date' is not in the proper format.
+// '05/01/1996' converts to 5/1/1996 12:00:00 AM Unspecified time.
+// 'Tue Apr 28, 2009' converts to 4/28/2009 12:00:00 AM Unspecified time.
+// 'Wed Apr 28, 2009' is not in the proper format.
+// '06 July 2008 7:32:47 AM' converts to 7/6/2008 7:32:47 AM Unspecified time.
+// '17:32:47.003' converts to 5/30/2008 5:32:47 PM Unspecified time.
+// 'Sat, 10 May 2008 14:32:17 GMT' converts to 5/10/2008 7:32:17 AM Local time.
+// '2009-05-01T07:54:59.9843750-04:00' converts to 5/1/2009 4:54:59 AM Local time.
+//
diff --git a/snippets/fsharp/System/Convert/ToDateTime/ToDateTime3.fs b/snippets/fsharp/System/Convert/ToDateTime/ToDateTime3.fs
new file mode 100644
index 00000000000..f6d0c86a1b4
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToDateTime/ToDateTime3.fs
@@ -0,0 +1,26 @@
+module ToDateTime3
+
+//
+open System
+open System.Globalization
+
+printfn $"""{"Date String",-18}{"Culture",-12}{"Result"}\n"""
+
+let cultureNames = [ "en-US"; "ru-RU"; "ja-JP" ]
+let dateStrings =
+ [ "01/02/09"; "2009/02/03"; "01/2009/03"
+ "01/02/2009"; "21/02/09"; "01/22/09"; "01/02/23" ]
+// Iterate each culture name in the array.
+for cultureName in cultureNames do
+ let culture = CultureInfo cultureName
+
+ // Parse each date using the designated culture.
+ for dateStr in dateStrings do
+ try
+ let dateTimeValue = Convert.ToDateTime(dateStr, culture)
+ // Display the date and time in a fixed format.
+ printfn $"""{dateStr,-18}{cultureName,-12}{dateTimeValue.ToString "yyyy-MMM-dd"}"""
+ with :? FormatException as e ->
+ printfn $"{dateStr,-18}{cultureName,-12}{e.GetType().Name}"
+ printfn ""
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToDateTime/fs.fsproj b/snippets/fsharp/System/Convert/ToDateTime/fs.fsproj
new file mode 100644
index 00000000000..7a5374e1f6c
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToDateTime/fs.fsproj
@@ -0,0 +1,11 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToDateTime/todatetime4.fs b/snippets/fsharp/System/Convert/ToDateTime/todatetime4.fs
new file mode 100644
index 00000000000..da305fd77fd
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToDateTime/todatetime4.fs
@@ -0,0 +1,69 @@
+module todatetime4
+
+//
+open System
+open System.Globalization
+
+type CustomProvider(cultureName: string) =
+ interface IFormatProvider with
+ member _.GetFormat(formatType) =
+ if formatType = typeof then
+ printf "(CustomProvider retrieved.) "
+ CultureInfo(cultureName).GetFormat formatType
+ else
+ null
+
+let cultureNames = [ "en-US"; "hu-HU"; "pt-PT" ]
+let objects: obj list =
+ [ 12; 17.2; false; DateTime(2010, 1, 1); "today"
+ System.Collections.ArrayList(); 'c'
+ "05/10/2009 6:13:18 PM"; "September 8, 1899" ]
+
+for cultureName in cultureNames do
+ printfn $"{cultureName} culture:"
+ let provider = CustomProvider cultureName
+ for obj in objects do
+ try
+ let dateValue = Convert.ToDateTime(obj, provider)
+ printfn $"{obj} --> {dateValue.ToString(CultureInfo cultureName)}"
+ with
+ | :? FormatException ->
+ printfn $"{obj} --> Bad Format"
+ | :? InvalidCastException ->
+ printfn $"{obj} --> Conversion Not Supported"
+ printfn ""
+
+// The example displays the following output:
+// en-US culture:
+// 12 --> Conversion Not Supported
+// 17.2 --> Conversion Not Supported
+// False --> Conversion Not Supported
+// 1/1/2010 12:00:00 AM --> 1/1/2010 12:00:00 AM
+// (CustomProvider retrieved.) today --> Bad Format
+// System.Collections.ArrayList --> Conversion Not Supported
+// c --> Conversion Not Supported
+// (CustomProvider retrieved.) 05/10/2009 6:13:18 PM --> 5/10/2009 6:13:18 PM
+// (CustomProvider retrieved.) September 8, 1899 --> 9/8/1899 12:00:00 AM
+//
+// hu-HU culture:
+// 12 --> Conversion Not Supported
+// 17.2 --> Conversion Not Supported
+// False --> Conversion Not Supported
+// 1/1/2010 12:00:00 AM --> 2010. 01. 01. 0:00:00
+// (CustomProvider retrieved.) today --> Bad Format
+// System.Collections.ArrayList --> Conversion Not Supported
+// c --> Conversion Not Supported
+// (CustomProvider retrieved.) 05/10/2009 6:13:18 PM --> 2009. 05. 10. 18:13:18
+// (CustomProvider retrieved.) September 8, 1899 --> 1899. 09. 08. 0:00:00
+//
+// pt-PT culture:
+// 12 --> Conversion Not Supported
+// 17.2 --> Conversion Not Supported
+// False --> Conversion Not Supported
+// 1/1/2010 12:00:00 AM --> 01-01-2010 0:00:00
+// (CustomProvider retrieved.) today --> Bad Format
+// System.Collections.ArrayList --> Conversion Not Supported
+// c --> Conversion Not Supported
+// (CustomProvider retrieved.) 05/10/2009 6:13:18 PM --> 05-10-2009 18:13:18
+// (CustomProvider retrieved.) September 8, 1899 --> 08-09-1899 0:00:00
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToDecimal/ToDecimal1.fs b/snippets/fsharp/System/Convert/ToDecimal/ToDecimal1.fs
new file mode 100644
index 00000000000..a2fadc744d1
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToDecimal/ToDecimal1.fs
@@ -0,0 +1,26 @@
+module ToDecimal1
+
+open System
+
+let convertSingleToDecimal () =
+ //
+ printfn $"{Convert.ToDecimal 1234567500.12F}" // Displays 1234568000
+ printfn $"{Convert.ToDecimal 1234568500.12F}" // Displays 1234568000
+
+ printfn $"{Convert.ToDecimal 10.980365F}" // Displays 10.98036
+ printfn $"{Convert.ToDecimal 10.980355F}" // Displays 10.98036
+ //
+
+let convertDoubleToDecimal () =
+ //
+ printfn $"{Convert.ToDecimal 123456789012345500.12}" // Displays 123456789012346000
+ printfn $"{Convert.ToDecimal 123456789012346500.12}" // Displays 123456789012346000
+
+ printfn $"{Convert.ToDecimal 10030.12345678905}" // Displays 10030.123456789
+ printfn $"{Convert.ToDecimal 10030.12345678915}" // Displays 10030.1234567892
+ //
+
+
+convertSingleToDecimal ()
+convertDoubleToDecimal ()
+
diff --git a/snippets/fsharp/System/Convert/ToDecimal/fs.fsproj b/snippets/fsharp/System/Convert/ToDecimal/fs.fsproj
new file mode 100644
index 00000000000..2852b368c70
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToDecimal/fs.fsproj
@@ -0,0 +1,12 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToDecimal/todecimal11.fs b/snippets/fsharp/System/Convert/ToDecimal/todecimal11.fs
new file mode 100644
index 00000000000..81a3f302836
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToDecimal/todecimal11.fs
@@ -0,0 +1,179 @@
+module todecimal11
+
+open System
+
+
+let convertBoolean () =
+ //
+ let flags = [ true; false ]
+
+ for flag in flags do
+ let result = Convert.ToDecimal flag
+ printfn $"Converted {flag} to {result}."
+ // The example displays the following output:
+ // Converted True to 1.
+ // Converted False to 0.
+ //
+
+let convertInt16 () =
+ //
+ let numbers =
+ [| Int16.MinValue; -1000s; 0s; 1000s; Int16.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToDecimal number
+ printfn $"Converted the Int16 value {number} to the Decimal value {result}."
+ // The example displays the following output:
+ // Converted the Int16 value -32768 to the Decimal value -32768.
+ // Converted the Int16 value -1000 to the Decimal value -1000.
+ // Converted the Int16 value 0 to the Decimal value 0.
+ // Converted the Int16 value 1000 to the Decimal value 1000.
+ // Converted the Int16 value 32767 to the Decimal value 32767.
+ //
+
+let convertInt32 () =
+ //
+ let numbers =
+ [| Int32.MinValue; -1000; 0; 1000; Int32.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToDecimal number
+ printfn $"Converted the Int32 value {number} to the Decimal value {result}."
+ // The example displays the following output:
+ // Converted the Int32 value -2147483648 to the Decimal value -2147483648.
+ // Converted the Int32 value -1000 to the Decimal value -1000.
+ // Converted the Int32 value 0 to the Decimal value 0.
+ // Converted the Int32 value 1000 to the Decimal value 1000.
+ // Converted the Int32 value 2147483647 to the Decimal value 2147483647.
+ //
+
+let convertObject () =
+ //
+ let values: obj[] =
+ [| true; 'a'; 123; 1.764e32; "9.78"; "1e-02"; 1.67e03
+ "A100"; "1,033.67"; DateTime.Now; Double.MaxValue |]
+
+ for value in values do
+ try
+ let result = Convert.ToDecimal value
+ printfn $"Converted the {value.GetType().Name} value {value} to {result}."
+ with
+ | :? OverflowException ->
+ printfn $"The {value.GetType().Name} value {value} is out of range of the Decimal type."
+ | :? FormatException ->
+ printfn $"The {value.GetType().Name} value {value} is not recognized as a valid Decimal value."
+ | :? InvalidCastException ->
+ printfn $"Conversion of the {value.GetType().Name} value {value} to a Decimal is not supported."
+ // The example displays the following output:
+ // Converted the Boolean value True to 1.
+ // Conversion of the Char value a to a Decimal is not supported.
+ // Converted the Int32 value 123 to 123.
+ // The Double value 1.764E+32 is out of range of the Decimal type.
+ // Converted the String value 9.78 to 9.78.
+ // The String value 1e-02 is not recognized as a valid Decimal value.
+ // Converted the Double value 1670 to 1670.
+ // The String value A100 is not recognized as a valid Decimal value.
+ // Converted the String value 1,033.67 to 1033.67.
+ // Conversion of the DateTime value 10/15/2008 05:40:42 PM to a Decimal is not supported.
+ // The Double value 1.79769313486232E+308 is out of range of the Decimal type.
+ //
+
+let convertSByte () =
+ //
+ let numbers =
+ [| SByte.MinValue, -23, 0, 17, SByte.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToDecimal number
+ printfn $"Converted the SByte value {number} to {result}."
+ // Converted the SByte value -128 to -128.
+ // Converted the SByte value -23 to -23.
+ // Converted the SByte value 0 to 0.
+ // Converted the SByte value 17 to 17.
+ // Converted the SByte value 127 to 127.
+ //
+
+let convertSingle () =
+ //
+ let numbers =
+ [| Single.MinValue; -3e10f; -1093.54f; 0f
+ 1e-03f; 1034.23f; Single.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToDecimal number
+ printfn $"Converted the Single value {number} to {result}."
+ with :? OverflowException ->
+ printfn $"{number} is out of range of the Decimal type."
+ // The example displays the following output:
+ // -3.402823E+38 is out of range of the Decimal type.
+ // Converted the Single value -3E+10 to -30000000000.
+ // Converted the Single value -1093.54 to -1093.54.
+ // Converted the Single value 0 to 0.
+ // Converted the Single value 0.001 to 0.001.
+ // Converted the Single value 1034.23 to 1034.23.
+ // 3.402823E+38 is out of range of the Decimal type.
+ //
+
+let convertUInt16 () =
+ //
+ let numbers =
+ [| UInt16.MinValue; 121us; 12345us; UInt16.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToDecimal number
+ printfn $"Converted the UInt16 value {number} to {result}."
+ // The example displays the following output:
+ // Converted the UInt16 value 0 to 0.
+ // Converted the UInt16 value 121 to 121.
+ // Converted the UInt16 value 12345 to 12345.
+ // Converted the UInt16 value 65535 to 65535.
+ //
+
+let convertUInt32 () =
+ //
+ let numbers =
+ [| UInt32.MinValue; 121u; 12345u; UInt32.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToDecimal number
+ printfn $"Converted the UInt32 value {number} to {result}."
+ // The example displays the following output:
+ // Converted the UInt32 value 0 to 0.
+ // Converted the UInt32 value 121 to 121.
+ // Converted the UInt32 value 12345 to 12345.
+ // Converted the UInt32 value 4294967295 to 4294967295.
+ //
+
+let convertUInt64 () =
+ //
+ let numbers =
+ [| UInt64.MinValue; 121uL; 12345uL; UInt64.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToDecimal number
+ printfn $"Converted the UInt64 value {number} to {result}."
+ // The example displays the following output:
+ // Converted the UInt64 value 0 to 0.
+ // Converted the UInt64 value 121 to 121.
+ // Converted the UInt64 value 12345 to 12345.
+ // Converted the UInt64 value 18446744073709551615 to 18446744073709551615.
+ //
+
+convertBoolean ()
+printfn "-----"
+convertInt16 ()
+printfn "-----"
+convertInt32 ()
+printfn "-----"
+convertObject ()
+printfn "-----"
+convertSByte ()
+printfn "-----"
+convertSingle ()
+printfn "-----"
+convertUInt16 ()
+printfn "-----"
+convertUInt32 ()
+printfn "-----"
+convertUInt64 ()
diff --git a/snippets/fsharp/System/Convert/ToDecimal/todecimal2.fs b/snippets/fsharp/System/Convert/ToDecimal/todecimal2.fs
new file mode 100644
index 00000000000..958cdfa02b0
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToDecimal/todecimal2.fs
@@ -0,0 +1,147 @@
+module todeci
+
+//
+open System
+open System.Globalization
+
+type Temperature(temperature) =
+ member _.Celsius = temperature
+
+ member _.Kelvin =
+ temperature + 273.15m
+
+ member _.Fahrenheit =
+ Math.Round(temperature * 9m / 5m + 32m, 2)
+
+ override _.ToString() =
+ $"{temperature:N2} °C"
+
+ // IConvertible implementations.
+ interface IConvertible with
+ member _.GetTypeCode() =
+ TypeCode.Object
+
+ member _.ToBoolean(provider: IFormatProvider) =
+ temperature <> 0M
+
+ member _.ToByte(provider: IFormatProvider) =
+ if uint8 temperature < Byte.MinValue || uint8 temperature > Byte.MaxValue then
+ raise (OverflowException $"{temperature} is out of range of the Byte type.")
+ else
+ Decimal.ToByte temperature
+
+ member _.ToChar(provider: IFormatProvider) =
+ raise (InvalidCastException "Temperature to Char conversion is not supported.")
+
+ member _.ToDateTime(provider: IFormatProvider) =
+ raise (InvalidCastException "Temperature to DateTime conversion is not supported.")
+
+ member _.ToDecimal(provider: IFormatProvider) =
+ temperature
+
+ member _.ToDouble(provider: IFormatProvider) =
+ Decimal.ToDouble temperature
+
+ member _.ToInt16(provider: IFormatProvider) =
+ if int16 temperature < Int16.MinValue || int16 temperature > Int16.MaxValue then
+ raise (OverflowException $"{temperature} is out of range of the Int16 type.")
+ else
+ Decimal.ToInt16 temperature
+
+ member _.ToInt32(provider: IFormatProvider) =
+ if int temperature < Int32.MinValue || int temperature > Int32.MaxValue then
+ raise (OverflowException $"{temperature} is out of range of the Int32 type.")
+ else
+ Decimal.ToInt32 temperature
+
+ member _.ToInt64(provider: IFormatProvider) =
+ if int64 temperature < Int64.MinValue || int64 temperature > Int64.MaxValue then
+ raise (OverflowException $"{temperature} is out of range of the Int64 type.")
+ else
+ Decimal.ToInt64 temperature
+
+ member _.ToSByte(provider: IFormatProvider) =
+ if int8 temperature < SByte.MinValue || int8 temperature > SByte.MaxValue then
+ raise (OverflowException $"{temperature} is out of range of the SByte type.")
+ else
+ Decimal.ToSByte temperature
+
+ member _.ToSingle(provider: IFormatProvider) =
+ Decimal.ToSingle temperature
+
+ member _.ToString(provider: IFormatProvider) =
+ temperature.ToString("N2", provider) + " °C"
+
+ member this.ToType(conversionType: Type, provider: IFormatProvider) =
+ let this = this :> IConvertible
+ match Type.GetTypeCode conversionType with
+ | TypeCode.Boolean ->
+ this.ToBoolean null
+ | TypeCode.Byte ->
+ this.ToByte null
+ | TypeCode.Char ->
+ this.ToChar null
+ | TypeCode.DateTime ->
+ this.ToDateTime null
+ | TypeCode.Decimal ->
+ this.ToDecimal null
+ | TypeCode.Double ->
+ this.ToDouble null
+ | TypeCode.Int16 ->
+ this.ToInt16 null
+ | TypeCode.Int32 ->
+ this.ToInt32 null
+ | TypeCode.Int64 ->
+ this.ToInt64 null
+ | TypeCode.Object ->
+ if typeof.Equals conversionType then
+ this
+ else
+ raise (InvalidCastException $"Conversion to a {conversionType.Name} is not supported.")
+ | TypeCode.SByte ->
+ this.ToSByte null
+ | TypeCode.Single ->
+ this.ToSingle null
+ | TypeCode.String ->
+ this.ToString provider
+ | TypeCode.UInt16 ->
+ this.ToUInt16 null
+ | TypeCode.UInt32 ->
+ this.ToUInt32 null
+ | TypeCode.UInt64 ->
+ this.ToUInt64 null
+ | _ ->
+ raise (InvalidCastException $"Conversion to {conversionType.Name} is not supported.")
+
+ member _.ToUInt16(provider: IFormatProvider) =
+ if uint16 temperature < UInt16.MinValue || uint16 temperature > UInt16.MaxValue then
+ raise (OverflowException $"{temperature} is out of range of the UInt16 type.")
+ else
+ Decimal.ToUInt16 temperature
+
+ member _.ToUInt32(provider: IFormatProvider) =
+ if uint temperature < UInt32.MinValue || uint temperature > UInt32.MaxValue then
+ raise (OverflowException $"{temperature} is out of range of the UInt32 type.")
+ else
+ Decimal.ToUInt32 temperature
+
+ member _.ToUInt64(provider: IFormatProvider) =
+ if uint64 temperature < UInt64.MinValue || uint64 temperature > UInt64.MaxValue then
+ raise (OverflowException $"{temperature} is out of range of the UInt64 type.")
+ else
+ Decimal.ToUInt64 temperature
+ //
+
+//
+let cold = Temperature -40
+let freezing = Temperature 0
+let boiling = Temperature 100
+
+printfn $"{Convert.ToDecimal(cold, null)}"
+printfn $"{Convert.ToDecimal(freezing, null)}"
+printfn $"{Convert.ToDecimal(boiling, null)}"
+// The example dosplays the following output:
+// -40
+// 0
+// 100
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToDecimal/todecimal3.fs b/snippets/fsharp/System/Convert/ToDecimal/todecimal3.fs
new file mode 100644
index 00000000000..7c8940c1a7f
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToDecimal/todecimal3.fs
@@ -0,0 +1,38 @@
+//
+open System
+open System.Globalization
+
+let values =
+ [| "123456789"; "12345.6789"; "12 345,6789"; "123,456.789"
+ "123 456,789"; "123,456,789.0123"; "123 456 789,0123" |]
+let cultures =
+ [ CultureInfo "en-US"; CultureInfo "fr-FR" ]
+
+for culture in cultures do
+ printfn $"String -> Decimal Conversion Using the {culture.Name} Culture"
+ for value in values do
+ printf $"{value,20} -> "
+ try
+ printfn $"{Convert.ToDecimal(value, culture)}"
+ with :? FormatException ->
+ printfn "FormatException"
+ printfn ""
+// The example displays the following output:
+// String -> Decimal Conversion Using the en-US Culture
+// 123456789 -> 123456789
+// 12345.6789 -> 12345.6789
+// 12 345,6789 -> FormatException
+// 123,456.789 -> 123456.789
+// 123 456,789 -> FormatException
+// 123,456,789.0123 -> 123456789.0123
+// 123 456 789,0123 -> FormatException
+//
+// String -> Decimal Conversion Using the fr-FR Culture
+// 123456789 -> 123456789
+// 12345.6789 -> FormatException
+// 12 345,6789 -> 12345.6789
+// 123,456.789 -> FormatException
+// 123 456,789 -> 123456.789
+// 123,456,789.0123 -> FormatException
+// 123 456 789,0123 -> 123456789.0123
+//
diff --git a/snippets/fsharp/System/Convert/ToDouble/example8.fs b/snippets/fsharp/System/Convert/ToDouble/example8.fs
new file mode 100644
index 00000000000..f47fbd4177e
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToDouble/example8.fs
@@ -0,0 +1,28 @@
+module example8
+
+//
+open System
+
+let values=
+ [| "-1,035.77219"; "1AFF"; "1e-35"
+ "1,635,592,999,999,999,999,999,999"; "-17.455"
+ "190.34001"; "1.29e325" |]
+
+for value in values do
+ try
+ let result = Convert.ToDouble value
+ printfn $"Converted '{value}' to {result}."
+ with
+ | :? FormatException ->
+ printfn $"Unable to convert '{value}' to a Double."
+ | :? OverflowException ->
+ printfn $"'{value}' is outside the range of a Double."
+// The example displays the following output:
+// Converted '-1,035.77219' to -1035.77219.
+// Unable to convert '1AFF' to a Double.
+// Converted '1e-35' to 1E-35.
+// Converted '1,635,592,999,999,999,999,999,999' to 1.635593E+24.
+// Converted '-17.455' to -17.455.
+// Converted '190.34001' to 190.34001.
+// '1.29e325' is outside the range of a Double.
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToDouble/fs.fsproj b/snippets/fsharp/System/Convert/ToDouble/fs.fsproj
new file mode 100644
index 00000000000..fe341724924
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToDouble/fs.fsproj
@@ -0,0 +1,11 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToDouble/todouble.fs b/snippets/fsharp/System/Convert/ToDouble/todouble.fs
new file mode 100644
index 00000000000..5f9090fc143
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToDouble/todouble.fs
@@ -0,0 +1,47 @@
+module todouble
+
+//
+open System
+open System.Globalization
+
+// Create a NumberFormatInfo object and set some of its properties.
+let provider =
+ NumberFormatInfo(NumberDecimalSeparator = ",", NumberGroupSeparator = ".", NumberGroupSizes = [| 3 |])
+
+// Define an array of numeric strings to convert.
+let values =
+ [| "123456789"
+ "12345.6789"
+ "12345,6789"
+ "123,456.789"
+ "123.456,789"
+ "123,456,789.0123"
+ "123.456.789,0123" |]
+
+printfn $"Default Culture: {CultureInfo.CurrentCulture.Name}\n"
+printfn $"""{"String to Convert", -22} {"Default/Exception", -20} {"Provider/Exception", -20}\n"""
+
+// Convert each string to a Double with and without the provider.
+for value in values do
+ printf $"{value, -22} "
+
+ try
+ printf $"{Convert.ToDouble value, -20} "
+ with :? FormatException as e -> printf $"{e.GetType().Name, -20} "
+
+ try
+ printfn $"{Convert.ToDouble(value, provider), -20} "
+ with :? FormatException as e -> printfn $"{e.GetType().Name, -20} "
+// The example displays the following output:
+// Default Culture: en-US
+//
+// String to Convert Default/Exception Provider/Exception
+//
+// 123456789 123456789 123456789
+// 12345.6789 12345.6789 123456789
+// 12345,6789 123456789 12345.6789
+// 123,456.789 123456.789 FormatException
+// 123.456,789 FormatException 123456.789
+// 123,456,789.0123 123456789.0123 FormatException
+// 123.456.789,0123 FormatException 123456789.0123
+//
diff --git a/snippets/fsharp/System/Convert/ToDouble/todouble1.fs b/snippets/fsharp/System/Convert/ToDouble/todouble1.fs
new file mode 100644
index 00000000000..8629cd004cf
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToDouble/todouble1.fs
@@ -0,0 +1,140 @@
+module todouble1
+
+open System
+
+
+let convertInt16 () =
+ //
+ let numbers =
+ [| Int16.MinValue; -1032s; 0s; 192s; Int16.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToDouble number
+ printfn $"Converted the UInt16 value {number} to {result}."
+ // The example displays the following output:
+ // Converted the UInt16 value -32768 to -32768.
+ // Converted the UInt16 value -1032 to -1032.
+ // Converted the UInt16 value 0 to 0.
+ // Converted the UInt16 value 192 to 192.
+ // Converted the UInt16 value 32767 to 32767.
+ //
+
+let convertInt64 () =
+ //
+ let numbers =
+ [| Int64.MinValue; -903L; 0L; 172L; Int64.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToDouble number
+ printfn $"Converted the {number.GetType().Name} value '{number}' to the {result.GetType().Name} value {result}."
+ // The example displays the following output:
+ // Converted the Int64 value '-9223372036854775808' to the Double value -9.22337203685478E+18.
+ // Converted the Int64 value '-903' to the Double value -903.
+ // Converted the Int64 value '0' to the Double value 0.
+ // Converted the Int64 value '172' to the Double value 172.
+ // Converted the Int64 value '9223372036854775807' to the Double value 9.22337203685478E+18.
+ //
+
+let convertObject () =
+ //
+ let values: obj[] =
+ [| true; 'a'; 123; 1.764e32f; "9.78"; "1e-02";
+ 1.67e03f; "A100"; "1,033.67"; DateTime.Now
+ Decimal.MaxValue |]
+
+ for value in values do
+ try
+ let result = Convert.ToDouble value
+ printfn $"Converted the {value.GetType().Name} value {value} to {result}."
+ with
+ | :? FormatException ->
+ printfn $"The {value.GetType().Name} value {value} is not recognized as a valid Double value."
+ | :? InvalidCastException ->
+ printfn $"Conversion of the {value.GetType().Name} value {value} to a Double is not supported."
+ // The example displays the following output:
+ // Converted the Boolean value True to 1.
+ // Conversion of the Char value a to a Double is not supported.
+ // Converted the Int32 value 123 to 123.
+ // Converted the Single value 1.764E+32 to 1.76399995098587E+32.
+ // Converted the String value 9.78 to 9.78.
+ // Converted the String value 1e-02 to 0.01.
+ // Converted the Single value 1670 to 1670.
+ // The String value A100 is not recognized as a valid Double value.
+ // Converted the String value 1,033.67 to 1033.67.
+ // Conversion of the DateTime value 10/21/2008 07:12:12 AM to a Double is not supported.
+ // Converted the Decimal value 79228162514264337593543950335 to 7.92281625142643E+28.
+ //
+
+let convertSByte () =
+ //
+ let numbers =
+ [| SByte.MinValue; -23y; 0y; 17y; SByte.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToDouble number
+ printfn $"Converted the SByte value {number} to {result}."
+ // Converted the SByte value -128 to -128.
+ // Converted the SByte value -23 to -23.
+ // Converted the SByte value 0 to 0.
+ // Converted the SByte value 17 to 17.
+ // Converted the SByte value 127 to 127.
+ //
+
+let convertUInt16 () =
+ //
+ let numbers =
+ [| UInt16.MinValue; 121us; 12345us; UInt16.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToDouble number
+ printfn $"Converted the UInt16 value {number} to {result}."
+ // The example displays the following output:
+ // Converted the UInt16 value 0 to 0.
+ // Converted the UInt16 value 121 to 121.
+ // Converted the UInt16 value 12345 to 12345.
+ // Converted the UInt16 value 65535 to 65535.
+ //
+
+let convertUInt32 () =
+ //
+ let numbers =
+ [| UInt32.MinValue; 121u; 12345u; UInt32.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToDouble number
+ printfn $"Converted the UInt32 value {number} to {result}."
+ // The example displays the following output:
+ // Converted the UInt32 value 0 to 0.
+ // Converted the UInt32 value 121 to 121.
+ // Converted the UInt32 value 12345 to 12345.
+ // Converted the UInt32 value 4294967295 to 4294967295.
+ //
+
+let convertUInt64 () =
+ //
+ let numbers =
+ [| UInt64.MinValue; 121uL; 12345uL; UInt64.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToDouble number
+ printfn $"Converted the UInt64 value {number} to {result}."
+ // The example displays the following output:
+ // Converted the UInt64 value 0 to 0.
+ // Converted the UInt64 value 121 to 121.
+ // Converted the UInt64 value 12345 to 12345.
+ // Converted the UInt64 value 18446744073709551615 to 1.84467440737096E+19.
+ //
+
+convertInt16 ()
+printfn "-----"
+convertInt64 ()
+printfn "-----"
+convertObject ()
+printfn "-----"
+convertSByte ()
+printfn "----"
+convertUInt16 ()
+printfn "-----"
+convertUInt32 ()
+printfn "------"
+convertUInt64 ()
diff --git a/snippets/fsharp/System/Convert/ToInt16/fs.fsproj b/snippets/fsharp/System/Convert/ToInt16/fs.fsproj
new file mode 100644
index 00000000000..81d0b1ee37a
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToInt16/fs.fsproj
@@ -0,0 +1,12 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToInt16/toint16.fs b/snippets/fsharp/System/Convert/ToInt16/toint16.fs
new file mode 100644
index 00000000000..18b96b37fef
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToInt16/toint16.fs
@@ -0,0 +1,90 @@
+module toint16
+
+//
+// Example of the Convert.ToInt16( string ) and
+// Convert.ToInt16( string, IFormatProvider ) methods.
+open System
+open System.Globalization
+
+let format obj1 obj2 obj3 = printfn $"{obj1,-20}{obj2,-20}{obj3}"
+
+// Get the exception type name; remove the namespace prefix.
+let getExceptionType (ex: exn) =
+ let exceptionType = ex.GetType() |> string
+ exceptionType.Substring(exceptionType.LastIndexOf '.' + 1)
+
+let convertToInt16 (numericStr: string) (provider: IFormatProvider) =
+ // Convert numericStr to Int16 without a format provider.
+ let defaultValue =
+ try
+ Convert.ToInt16 numericStr
+ |> string
+ with ex ->
+ getExceptionType ex
+
+ // Convert numericStr to Int16 with a format provider.
+ let providerValue =
+ try
+ Convert.ToInt16(numericStr, provider)
+ |> string
+ with ex ->
+ getExceptionType ex
+
+ format numericStr defaultValue providerValue
+
+// Create a NumberFormatInfo object and set several of its
+// properties that apply to numbers.
+let provider = NumberFormatInfo()
+
+// These properties affect the conversion.
+provider.NegativeSign <- "neg "
+provider.PositiveSign <- "pos "
+
+// These properties do not affect the conversion.
+// The input string cannot have decimal and group separators.
+provider.NumberDecimalSeparator <- "."
+provider.NumberGroupSeparator <- ","
+provider.NumberGroupSizes <- [| 3 |]
+provider.NumberNegativePattern <- 0
+
+printfn
+ """This example of
+ Convert.ToInt16( string ) and
+ Convert.ToInt16( string, IFormatProvider )
+generates the following output. It converts several strings to
+short values, using default formatting or a NumberFormatInfo object.
+"""
+format "String to convert" "Default/exception" "Provider/exception"
+format "-----------------" "-----------------" "------------------"
+
+// Convert strings, with and without an IFormatProvider.
+convertToInt16 "12345" provider
+convertToInt16 "+12345" provider
+convertToInt16 "pos 12345" provider
+convertToInt16 "-12345" provider
+convertToInt16 "neg 12345" provider
+convertToInt16 "12345." provider
+convertToInt16 "12,345" provider
+convertToInt16 "(12345)" provider
+convertToInt16 "32768" provider
+convertToInt16 "-32769" provider
+
+// This example of
+// Convert.ToInt16( string ) and
+// Convert.ToInt16( string, IFormatProvider )
+// generates the following output. It converts several strings to
+// short values, using default formatting or a NumberFormatInfo object.
+//
+// String to convert Default/exception Provider/exception
+// ----------------- ----------------- ------------------
+// 12345 12345 12345
+// +12345 12345 FormatException
+// pos 12345 FormatException 12345
+// -12345 -12345 FormatException
+// neg 12345 FormatException -12345
+// 12345. FormatException FormatException
+// 12,345 FormatException FormatException
+// (12345) FormatException FormatException
+// 32768 OverflowException OverflowException
+// -32769 OverflowException FormatException
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToInt16/toint16_1.fs b/snippets/fsharp/System/Convert/ToInt16/toint16_1.fs
new file mode 100644
index 00000000000..fd629b0719f
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToInt16/toint16_1.fs
@@ -0,0 +1,286 @@
+module toint16_1
+
+open System
+
+let convertBoolean () =
+ //
+ let falseFlag = false
+ let trueFlag = true
+
+ printfn $"{falseFlag} converts to {Convert.ToInt16 falseFlag}."
+ printfn $"{trueFlag} converts to {Convert.ToInt16 trueFlag}."
+ // The example displays the following output:
+ // False converts to 0.
+ // True converts to 1.
+ //
+
+let convertByte () =
+ //
+ let bytes = [| Byte.MinValue; 14uy; 122uy; Byte.MaxValue |]
+
+ for byteValue in bytes do
+ let result = Convert.ToInt16 byteValue
+ printfn $"The Byte value {byteValue} converts to {result}."
+ // The example displays the following output:
+ // The Byte value 0 converts to 0.
+ // The Byte value 14 converts to 14.
+ // The Byte value 122 converts to 122.
+ // The Byte value 255 converts to 255.
+ //
+
+let convertChar () =
+ //
+ let chars =
+ [| 'a'; 'z'; '\u0007'; '\u03FF'; '\u7FFF'; '\uFFFE' |]
+
+ for ch in chars do
+ try
+ let result = Convert.ToInt16 ch
+ printfn $"'{ch}' converts to {result}."
+ with :? OverflowException ->
+ printfn $"Unable to convert u+{int ch:X4} to an Int16."
+ // The example displays the following output:
+ // 'a' converts to 97.
+ // 'z' converts to 122.
+ // '' converts to 7.
+ // 'Ͽ' converts to 1023.
+ // '翿' converts to 32767.
+ // Unable to convert u+FFFE to an Int16.
+ //
+
+let convertDecimal () =
+ //
+ let values =
+ [| Decimal.MinValue; -1034.23m; -12m; 0m
+ 147m; 9214.16m; Decimal.MaxValue |]
+
+ for value in values do
+ try
+ let result = Convert.ToInt16 value
+ printfn $"Converted {value} to {result}."
+ with :? OverflowException ->
+ printfn $"{value} is outside the range of the Int16 type."
+ // The example displays the following output:
+ // -79228162514264337593543950335 is outside the range of the Int16 type.
+ // Converted -1034.23 to -1034.
+ // Converted -12 to -12.
+ // Converted 0 to 0.
+ // Converted 147 to 147.
+ // Converted 9214.16 to 9214.
+ // 79228162514264337593543950335 is outside the range of the Int16 type.
+ //
+
+let convertDouble () =
+ //
+ let values =
+ [| Double.MinValue; -1.38e10; -1023.299; -12.98
+ 0; 9.113e-16; 103.919; 17834.191; Double.MaxValue |]
+
+ for value in values do
+ try
+ let result = Convert.ToInt16 value
+ printfn $"Converted {value} to {result}."
+ with :? OverflowException ->
+ printfn $"{value} is outside the range of the Int16 type."
+ // -1.79769313486232E+308 is outside the range of the Int16 type.
+ // -13800000000 is outside the range of the Int16 type.
+ // Converted -1023.299 to -1023.
+ // Converted -12.98 to -13.
+ // Converted 0 to 0.
+ // Converted 9.113E-16 to 0.
+ // Converted 103.919 to 104.
+ // Converted 17834.191 to 17834.
+ // 1.79769313486232E+308 is outside the range of the Int16 type.
+ //
+
+let convertInt32 () =
+ //
+ let numbers =
+ [| Int32.MinValue; -1; 0; 121; 340; Int32.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToInt16 number
+ printfn $"Converted the {number.GetType().Name} value {number} to a {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"The {number.GetType().Name} value {number} is outside the range of the Int16 type."
+ // The example displays the following output:
+ // The Int32 value -2147483648 is outside the range of the Int16 type.
+ // Converted the Int32 value -1 to a Int16 value -1.
+ // Converted the Int32 value 0 to a Int16 value 0.
+ // Converted the Int32 value 121 to a Int16 value 121.
+ // Converted the Int32 value 340 to a Int16 value 340.
+ // The Int32 value 2147483647 is outside the range of the Int16 type.
+ //
+
+let convertInt64 () =
+ //
+ let numbers =
+ [| Int64.MinValue; -1; 0; 121; 340; Int64.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToInt16 number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"The {number.GetType().Name} value {number} is outside the range of the Int16 type."
+ // The example displays the following output:
+ // The Int64 value -9223372036854775808 is outside the range of the Int16 type.
+ // Converted the Int64 value -1 to the Int16 value -1.
+ // Converted the Int64 value 0 to the Int16 value 0.
+ // Converted the Int64 value 121 to the Int16 value 121.
+ // Converted the Int64 value 340 to the Int16 value 340.
+ // The Int64 value 9223372036854775807 is outside the range of the Int16 type.
+ //
+
+let convertObject () =
+ //
+ let values: obj[] =
+ [| true; -12; 163; 935; 'x'; DateTime(2009, 5, 12)
+ "104"; "103.0"; "-1"; "1.00e2"; "One"; 1.00e2 |]
+
+ for value in values do
+ try
+ let result = Convert.ToInt16 value
+ printfn $"Converted the {value.GetType().Name} value {value} to the {result.GetType().Name} value {result}."
+ with
+ | :? OverflowException ->
+ printfn $"The {value.GetType().Name} value {value} is outside the range of the Int16 type."
+ | :? FormatException ->
+ printfn $"The {value.GetType().Name} value {value} is not in a recognizable format."
+ | :? InvalidCastException ->
+ printfn $"No conversion to an Int16 exists for the {value.GetType().Name} value {value}."
+ // The example displays the following output:
+ // Converted the Boolean value True to the Int16 value 1.
+ // Converted the Int32 value -12 to the Int16 value -12.
+ // Converted the Int32 value 163 to the Int16 value 163.
+ // Converted the Int32 value 935 to the Int16 value 935.
+ // Converted the Char value x to the Int16 value 120.
+ // No conversion to an Int16 exists for the DateTime value 5/12/2009 12:00:00 AM.
+ // Converted the String value 104 to the Int16 value 104.
+ // The String value 103.0 is not in a recognizable format.
+ // Converted the String value -1 to the Int16 value -1.
+ // The String value 1.00e2 is not in a recognizable format.
+ // The String value One is not in a recognizable format.
+ // Converted the Double value 100 to the Int16 value 100.
+ //
+
+let convertSByte () =
+ //
+ let numbers =
+ [| SByte.MinValue; -1y; 0y; 10y; SByte.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToInt16 number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ // The example displays the following output:
+ // Converted the SByte value -128 to the Int16 value -128.
+ // Converted the SByte value -1 to the Int16 value -1.
+ // Converted the SByte value 0 to the Int16 value 0.
+ // Converted the SByte value 10 to the Int16 value 10.
+ // Converted the SByte value 127 to the Int16 value 127.
+ //
+
+let convertSingle () =
+ //
+ let values =
+ [| Single.MinValue; -1.38e10f; -1023.299f; -12.98f
+ 0f; 9.113e-16f; 103.919f; 17834.191f; Single.MaxValue |]
+
+ for value in values do
+ try
+ let result = Convert.ToInt16 value
+ printfn $"Converted the {value.GetType().Name} value {value} to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"{value} is outside the range of the Int16 type."
+ // The example displays the following output:
+ // -3.4028235E+38 is outside the range of the Int16 type.
+ // -1.38E+10 is outside the range of the Int16 type.
+ // Converted the Single value -1023.299 to the Int16 value -1023.
+ // Converted the Single value -12.98 to the Int16 value -13.
+ // Converted the Single value 0 to the Int16 value 0.
+ // Converted the Single value 9.113E-16 to the Int16 value 0.
+ // Converted the Single value 103.919 to the Int16 value 104.
+ // Converted the Single value 17834.191 to the Int16 value 17834.
+ // 3.4028235E+38 is outside the range of the Int16 type.
+ //
+
+let convertUInt16 () =
+ //
+ let numbers =
+ [| UInt16.MinValue; 121us; 340us; UInt16.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToInt16 number
+ printfn $"Converted the {number.GetType().Name} value {number} to a {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"The {number.GetType().Name} value {number} is outside the range of the Int16 type."
+ // The example displays the following output:
+ // Converted the UInt16 value 0 to a Int16 value 0.
+ // Converted the UInt16 value 121 to a Int16 value 121.
+ // Converted the UInt16 value 340 to a Int16 value 340.
+ // The UInt16 value 65535 is outside the range of the Int16 type.
+ //
+
+let convertUInt32 () =
+ //
+ let numbers =
+ [| UInt32.MinValue; 121u; 340u; UInt32.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToInt16 number
+ printfn $"Converted the {number.GetType().Name} value {number} to a {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"The {number.GetType().Name} value {number} is outside the range of the Int16 type."
+ // The example displays the following output:
+ // Converted the UInt32 value 0 to a Int16 value 0.
+ // Converted the UInt32 value 121 to a Int16 value 121.
+ // Converted the UInt32 value 340 to a Int16 value 340.
+ // The UInt32 value 4294967295 is outside the range of the Int16 type.
+ //
+
+let convertUInt64 () =
+ //
+ let numbers =
+ [| UInt64.MinValue; 121uL; 340uL; UInt64.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToInt16 number
+ printfn $"Converted the {number.GetType().Name} value {number} to a {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"The {number.GetType().Name} value {number} is outside the range of the Int16 type."
+ // The example displays the following output:
+ // Converted the UInt64 value 0 to a Int16 value 0.
+ // Converted the UInt64 value 121 to a Int16 value 121.
+ // Converted the UInt64 value 340 to a Int16 value 340.
+ // The UInt64 value 18446744073709551615 is outside the range of the Int16 type.
+ //
+
+convertBoolean ()
+printfn "-----"
+convertByte ()
+printfn "-----"
+convertChar ()
+printfn "-----"
+convertDecimal ()
+printfn "-----"
+convertDouble ()
+printfn "-----"
+convertInt32 ()
+printfn "-----"
+convertInt64 ()
+printfn "-----"
+convertObject ()
+printfn "-----"
+convertSByte ()
+printfn "-----"
+convertSingle ()
+printfn "----"
+convertUInt16 ()
+printfn "-----"
+convertUInt32 ()
+printfn "-----"
+convertUInt64 ()
diff --git a/snippets/fsharp/System/Convert/ToInt16/toint16_2.fs b/snippets/fsharp/System/Convert/ToInt16/toint16_2.fs
new file mode 100644
index 00000000000..a8022506aa4
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToInt16/toint16_2.fs
@@ -0,0 +1,30 @@
+module toint16_2
+
+//
+open System
+
+let hexStrings =
+ [| "8000"; "0FFF"; "f000"; "00A30"
+ "D"; "-13"; "9AC61"; "GAD" |]
+
+for hexString in hexStrings do
+ try
+ let number = Convert.ToInt16(hexString, 16)
+ printfn $"Converted '{hexString}' to {number:N0}."
+ with
+ | :? FormatException ->
+ printfn $"'{hexString}' is not in the correct format for a hexadecimal number."
+ | :? OverflowException ->
+ printfn $"'{hexString}' is outside the range of an Int16."
+ | :? ArgumentException ->
+ printfn $"'{hexString}' is invalid in base 16."
+// The example displays the following output:
+// Converted '8000' to -32,768.
+// Converted '0FFF' to 4,095.
+// Converted 'f000' to -4,096.
+// Converted '00A30' to 2,608.
+// Converted 'D' to 13.
+// '-13' is invalid in base 16.
+// '9AC61' is outside the range of an Int16.
+// 'GAD' is not in the correct format for a hexadecimal number.
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToInt16/tosbyte.fs b/snippets/fsharp/System/Convert/ToInt16/tosbyte.fs
new file mode 100644
index 00000000000..8d417c575e0
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToInt16/tosbyte.fs
@@ -0,0 +1,87 @@
+module tosbyte
+
+//
+// Example of the Convert.ToSByte( string ) and
+// Convert.ToSByte( string, IFormatProvider ) methods.
+open System
+open System.Globalization
+
+let format obj1 obj2 obj3 = printfn $"{obj1,-20}{obj2,-20}{obj3}"
+
+// Get the exception type name; remove the namespace prefix.
+let getExceptionType (ex: exn) =
+ let exceptionType = ex.GetType() |> string
+ exceptionType.Substring(exceptionType.LastIndexOf '.' + 1 )
+
+let convertToSByte (numericStr: string) (provider: IFormatProvider) =
+ // Convert numericStr to SByte without a format provider.
+ let defaultValue =
+ try
+ Convert.ToSByte numericStr
+ |> string
+ with ex ->
+ getExceptionType ex
+
+ // Convert numericStr to SByte with a format provider.
+ let providerValue =
+ try
+ Convert.ToSByte(numericStr, provider)
+ |> string
+ with ex ->
+ getExceptionType ex
+
+ format numericStr defaultValue providerValue
+
+// Create a NumberFormatInfo object and set several of its
+// properties that apply to numbers.
+let provider = NumberFormatInfo()
+
+// These properties affect the conversion.
+provider.NegativeSign <- "neg "
+provider.PositiveSign <- "pos "
+
+// These properties do not affect the conversion.
+// The input string cannot have decimal and group separators.
+provider.NumberDecimalSeparator <- "."
+provider.NumberNegativePattern <- 0
+
+printfn
+ """This example of
+ Convert.ToSByte( string ) and
+ Convert.ToSByte( string, IFormatProvider )
+generates the following output. It converts several strings to
+SByte values, using default formatting or a NumberFormatInfo object.
+"""
+format "String to convert" "Default/exception" "Provider/exception"
+format "-----------------" "-----------------" "------------------"
+
+// Convert strings, with and without an IFormatProvider.
+convertToSByte "123" provider
+convertToSByte "+123" provider
+convertToSByte "pos 123" provider
+convertToSByte "-123" provider
+convertToSByte "neg 123" provider
+convertToSByte "123." provider
+convertToSByte "(123)" provider
+convertToSByte "128" provider
+convertToSByte "-129" provider
+
+
+// This example of
+// Convert.ToSByte( string ) and
+// Convert.ToSByte( string, IFormatProvider )
+// generates the following output. It converts several strings to
+// SByte values, using default formatting or a NumberFormatInfo object.
+
+// String to convert Default/exception Provider/exception
+// ----------------- ----------------- ------------------
+// 123 123 123
+// +123 123 FormatException
+// pos 123 FormatException 123
+// -123 -123 FormatException
+// neg 123 FormatException -123
+// 123. FormatException FormatException
+// (123) FormatException FormatException
+// 128 OverflowException OverflowException
+// -129 OverflowException FormatException
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToInt32/fs.fsproj b/snippets/fsharp/System/Convert/ToInt32/fs.fsproj
new file mode 100644
index 00000000000..9047e42316a
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToInt32/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToInt32/toint32_1.fs b/snippets/fsharp/System/Convert/ToInt32/toint32_1.fs
new file mode 100644
index 00000000000..76fdbfb85a0
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToInt32/toint32_1.fs
@@ -0,0 +1,316 @@
+module toint32_1
+
+open System
+
+let convertBoolean () =
+ //
+ let falseFlag = false
+ let trueFlag = true
+
+ printfn $"{falseFlag} converts to {Convert.ToInt32 falseFlag}."
+ printfn $"{trueFlag} converts to {Convert.ToInt32 trueFlag}."
+ // The example displays the following output:
+ // False converts to 0.
+ // True converts to 1.
+ //
+
+let convertByte () =
+ //
+ let bytes =
+ [| Byte.MinValue; 14uy; 122uy; Byte.MaxValue |]
+
+ for byteValue in bytes do
+ let result = Convert.ToInt32 byteValue
+ printfn $"Converted the {byteValue.GetType().Name} value {byteValue} to the {result.GetType().Name} value {result}."
+ // The example displays the following output:
+ // Converted the Byte value 0 to the Int32 value 0.
+ // Converted the Byte value 14 to the Int32 value 14.
+ // Converted the Byte value 122 to the Int32 value 122.
+ // Converted the Byte value 255 to the Int32 value 255.
+ //
+
+let convertChar () =
+ //
+ let chars =
+ [| 'a'; 'z'; '\u0007'; '\u03FF'; '\u7FFF'; '\uFFFE' |]
+
+ for ch in chars do
+ try
+ let result = Convert.ToInt32 ch
+ printfn $"Converted the {ch.GetType().Name} value '{ch}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"Unable to convert u+{int ch:X4} to an Int32."
+ // The example displays the following output:
+ // Converted the Char value 'a' to the Int32 value 97.
+ // Converted the Char value 'z' to the Int32 value 122.
+ // Converted the Char value '' to the Int32 value 7.
+ // Converted the Char value 'Ͽ' to the Int32 value 1023.
+ // Converted the Char value '翿' to the Int32 value 32767.
+ // Converted the Char value '' to the Int32 value 65534.
+ //
+
+let convertDecimal () =
+ //
+ let values =
+ [| Decimal.MinValue; -1034.23m; -12m; 0m; 147m
+ 199.55m; 9214.16m; Decimal.MaxValue |]
+
+ for value in values do
+ try
+ let result = Convert.ToInt32 value
+ printfn $"Converted the {value.GetType().Name} value '{value}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"{value} is outside the range of the Int32 type."
+ // The example displays the following output:
+ // -79228162514264337593543950335 is outside the range of the Int32 type.
+ // Converted the Decimal value '-1034.23' to the Int32 value -1034.
+ // Converted the Decimal value '-12' to the Int32 value -12.
+ // Converted the Decimal value '0' to the Int32 value 0.
+ // Converted the Decimal value '147' to the Int32 value 147.
+ // Converted the Decimal value '199.55' to the Int32 value 200.
+ // Converted the Decimal value '9214.16' to the Int32 value 9214.
+ // 79228162514264337593543950335 is outside the range of the Int32 type.
+ //
+
+let convertDouble () =
+ //
+ let values =
+ [| Double.MinValue; -1.38e10; -1023.299; -12.98
+ 0; 9.113e-16; 103.919; 17834.191; Double.MaxValue |]
+
+ for value in values do
+ try
+ let result = Convert.ToInt32 value
+ printfn $"Converted the {value.GetType().Name} value '{value}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"{value} is outside the range of the Int32 type."
+ // -1.79769313486232E+308 is outside the range of the Int32 type.
+ // -13800000000 is outside the range of the Int32 type.
+ // Converted the Double value '-1023.299' to the Int32 value -1023.
+ // Converted the Double value '-12.98' to the Int32 value -13.
+ // Converted the Double value '0' to the Int32 value 0.
+ // Converted the Double value '9.113E-16' to the Int32 value 0.
+ // Converted the Double value '103.919' to the Int32 value 104.
+ // Converted the Double value '17834.191' to the Int32 value 17834.
+ // 1.79769313486232E+308 is outside the range of the Int32 type.
+ //
+
+let convertInt16 () =
+ //
+ let numbers =
+ [| Int16.MinValue; -1s; 0s; 121s; 340s; Int16.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToInt32 number
+ printfn $"Converted the {number.GetType().Name} value {number} to a {result.GetType().Name} value {result}."
+ // The example displays the following output:
+ // Converted the Int16 value -32768 to a Int32 value -32768.
+ // Converted the Int16 value -1 to a Int32 value -1.
+ // Converted the Int16 value 0 to a Int32 value 0.
+ // Converted the Int16 value 121 to a Int32 value 121.
+ // Converted the Int16 value 340 to a Int32 value 340.
+ // Converted the Int16 value 32767 to a Int32 value 32767.
+ //
+
+let convertInt64 () =
+ //
+ let numbers =
+ [| Int64.MinValue; -1; 0; 121; 340; Int64.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToInt32 number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"The {number.GetType().Name} value {number} is outside the range of the Int32 type."
+ // The example displays the following output:
+ // The Int64 value -9223372036854775808 is outside the range of the Int32 type.
+ // Converted the Int64 value -1 to the Int32 value -1.
+ // Converted the Int64 value 0 to the Int32 value 0.
+ // Converted the Int64 value 121 to the Int32 value 121.
+ // Converted the Int64 value 340 to the Int32 value 340.
+ // The Int64 value 9223372036854775807 is outside the range of the Int32 type.
+ //
+
+let convertObject () =
+ //
+ let values: obj[] =
+ [| true; -12; 163; 935; 'x'; DateTime(2009, 5, 12)
+ "104"; "103.0"; "-1"
+ "1.00e2"; "One"; 1.00e2; 16.3e42 |]
+
+ for value in values do
+ try
+ let result = Convert.ToInt32 value
+ printfn $"Converted the {value.GetType().Name} value {value} to the {result.GetType().Name} value {result}."
+ with
+ | :? OverflowException ->
+ printfn $"The {value.GetType().Name} value {value} is outside the range of the Int32 type."
+ | :? FormatException ->
+ printfn $"The {value.GetType().Name} value {value} is not in a recognizable format."
+ | :? InvalidCastException ->
+ printfn $"No conversion to an Int32 exists for the {value.GetType().Name} value {value}."
+ // The example displays the following output:
+ // Converted the Boolean value True to the Int32 value 1.
+ // Converted the Int32 value -12 to the Int32 value -12.
+ // Converted the Int32 value 163 to the Int32 value 163.
+ // Converted the Int32 value 935 to the Int32 value 935.
+ // Converted the Char value x to the Int32 value 120.
+ // No conversion to an Int32 exists for the DateTime value 5/12/2009 12:00:00 AM.
+ // Converted the String value 104 to the Int32 value 104.
+ // The String value 103.0 is not in a recognizable format.
+ // Converted the String value -1 to the Int32 value -1.
+ // The String value 1.00e2 is not in a recognizable format.
+ // The String value One is not in a recognizable format.
+ // Converted the Double value 100 to the Int32 value 100.
+ // The Double value 1.63E+43 is outside the range of the Int32 type.
+ //
+
+let convertSByte () =
+ //
+ let numbers =
+ [| SByte.MinValue; -1y; 0y; 10y; SByte.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToInt32 number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ // The example displays the following output:
+ // Converted the SByte value -128 to the Int32 value -128.
+ // Converted the SByte value -1 to the Int32 value -1.
+ // Converted the SByte value 0 to the Int32 value 0.
+ // Converted the SByte value 10 to the Int32 value 10.
+ // Converted the SByte value 127 to the Int32 value 127.
+ //
+
+let convertSingle () =
+ //
+ let values =
+ [| Single.MinValue; -1.38e10f; -1023.299f; -12.98f
+ 0f; 9.113e-16f; 103.919f; 17834.191f; Single.MaxValue |]
+
+ for value in values do
+ try
+ let result = Convert.ToInt32 value
+ printfn $"Converted the {value.GetType().Name} value {value} to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"{value} is outside the range of the Int32 type."
+ // The example displays the following output:
+ // -3.40282346638529E+38 is outside the range of the Int32 type.
+ // -13799999488 is outside the range of the Int32 type.
+ // Converted the Double value -1023.29901123047 to the Int32 value -1023.
+ // Converted the Double value -12.9799995422363 to the Int32 value -13.
+ // Converted the Double value 0 to the Int32 value 0.
+ // Converted the Double value 9.11299983940444E-16 to the Int32 value 0.
+ // Converted the Double value 103.918998718262 to the Int32 value 104.
+ // Converted the Double value 17834.19140625 to the Int32 value 17834.
+ // 3.40282346638529E+38 is outside the range of the Int32 type.
+ //
+
+let convertString () =
+ //
+ let values =
+ [| "One"; "1.34e28"; "-26.87"; "-18"; "-6.00"
+ " 0"; "137"; "1601.9"; string Int32.MaxValue |]
+
+ for value in values do
+ try
+ let result = Convert.ToInt32 value
+ printfn $"Converted the {value.GetType().Name} value {value} to the {result.GetType().Name} value {result}."
+ with
+ | :? OverflowException ->
+ printfn $"{value} is outside the range of the Int32 type."
+ | :? FormatException ->
+ printfn $"The {value.GetType().Name} value '{value}' is not in a recognizable format."
+ // The example displays the following output:
+ // The String value 'One' is not in a recognizable format.
+ // The String value '1.34e28' is not in a recognizable format.
+ // The String value '-26.87' is not in a recognizable format.
+ // Converted the String value '-18' to the Int32 value -18.
+ // The String value '-6.00' is not in a recognizable format.
+ // Converted the String value ' 0' to the Int32 value 0.
+ // Converted the String value '137' to the Int32 value 137.
+ // The String value '1601.9' is not in a recognizable format.
+ // Converted the String value '2147483647' to the Int32 value 2147483647.
+ //
+
+let convertUInt16 () =
+ //
+ let numbers =
+ [| UInt16.MinValue; 121us; 340us; UInt16.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToInt32 number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"The {number.GetType().Name} value {number} is outside the range of the Int32 type."
+ // The example displays the following output:
+ // Converted the UInt16 value 0 to the Int32 value 0.
+ // Converted the UInt16 value 121 to the Int32 value 121.
+ // Converted the UInt16 value 340 to the Int32 value 340.
+ // Converted the UInt16 value 65535 to the Int32 value 65535.
+ //
+
+let convertUInt32 () =
+ //
+ let numbers =
+ [| UInt32.MinValue; 121u; 340u; UInt32.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToInt32 number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"The {number.GetType().Name} value {number} is outside the range of the Int32 type."
+ // The example displays the following output:
+ // Converted the UInt32 value 0 to the Int32 value 0.
+ // Converted the UInt32 value 121 to the Int32 value 121.
+ // Converted the UInt32 value 340 to the Int32 value 340.
+ // The UInt32 value 4294967295 is outside the range of the Int32 type.
+ //
+
+let convertUInt64 () =
+ //
+ let numbers =
+ [| UInt64.MinValue; 121uL; 340uL; UInt64.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToInt32 number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"The {number.GetType().Name} value {number} is outside the range of the Int32 type."
+ // The example displays the following output:
+ // Converted the UInt64 value 0 to a Int32 value 0.
+ // Converted the UInt64 value 121 to a Int32 value 121.
+ // Converted the UInt64 value 340 to a Int32 value 340.
+ // The UInt64 value 18446744073709551615 is outside the range of the Int32 type.
+ //
+
+convertBoolean ()
+printfn "-----"
+convertByte ()
+printfn "-----"
+convertChar ()
+printfn "-----"
+convertDecimal ()
+printfn "-----"
+convertDouble ()
+printfn "-----"
+convertInt16 ()
+printfn "-----"
+convertInt64 ()
+printfn "-----"
+convertObject ()
+printfn "-----"
+convertSByte ()
+printfn "-----"
+convertSingle ()
+printfn "----"
+convertString ()
+printfn "-----"
+convertUInt16 ()
+printfn "-----"
+convertUInt32 ()
+printfn "-----"
+convertUInt64 ()
diff --git a/snippets/fsharp/System/Convert/ToInt32/toint32_2.fs b/snippets/fsharp/System/Convert/ToInt32/toint32_2.fs
new file mode 100644
index 00000000000..993475c5fe7
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToInt32/toint32_2.fs
@@ -0,0 +1,60 @@
+//
+open System
+open System.Globalization
+
+// Create a custom NumberFormatInfo object and set its two properties
+// used by default in parsing numeric strings.
+let customProvider = NumberFormatInfo()
+customProvider.NegativeSign <- "neg "
+customProvider.PositiveSign <- "pos "
+
+// Add custom and invariant provider to an array of providers.
+let providers =
+ [| customProvider; NumberFormatInfo.InvariantInfo |]
+
+// Define an array of strings to convert.
+let numericStrings =
+ [| "123456789"; "+123456789"; "pos 123456789"
+ "-123456789"; "neg 123456789"; "123456789."
+ "123,456,789"; "(123456789)"; "2147483648"
+ "-2147483649"; |]
+
+// Use each provider to parse all the numeric strings.
+for i = 0 to 1 do
+ let provider = providers[i]
+ printfn $"""{if i = 0 then "Custom Provider:" else "Invariant Provider:"}"""
+ for numericString in numericStrings do
+ printf $"{numericString,15} --> "
+ try
+ printfn $"{Convert.ToInt32(numericString, provider),20}"
+ with
+ | :? FormatException ->
+ printfn "%20s" "FormatException"
+ | :? OverflowException ->
+ printfn "%20s" "OverflowException"
+ printfn ""
+// The example displays the following output:
+// Custom Provider:
+// 123456789 --> 123456789
+// +123456789 --> FormatException
+// pos 123456789 --> 123456789
+// -123456789 --> FormatException
+// neg 123456789 --> -123456789
+// 123456789. --> FormatException
+// 123,456,789 --> FormatException
+// (123456789) --> FormatException
+// 2147483648 --> OverflowException
+// -2147483649 --> FormatException
+//
+// Invariant Provider:
+// 123456789 --> 123456789
+// +123456789 --> 123456789
+// pos 123456789 --> FormatException
+// -123456789 --> -123456789
+// neg 123456789 --> FormatException
+// 123456789. --> FormatException
+// 123,456,789 --> FormatException
+// (123456789) --> FormatException
+// 2147483648 --> OverflowException
+// -2147483649 --> OverflowException
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToInt64/fs.fsproj b/snippets/fsharp/System/Convert/ToInt64/fs.fsproj
new file mode 100644
index 00000000000..261d441919b
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToInt64/fs.fsproj
@@ -0,0 +1,11 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToInt64/toint64_1.fs b/snippets/fsharp/System/Convert/ToInt64/toint64_1.fs
new file mode 100644
index 00000000000..212e0d221a0
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToInt64/toint64_1.fs
@@ -0,0 +1,316 @@
+module toint53_1
+
+open System
+
+let convertBoolean () =
+ //
+ let falseFlag = false
+ let trueFlag = true
+
+ printfn $"{falseFlag} converts to {Convert.ToInt64 falseFlag}."
+ printfn $"{trueFlag} converts to {Convert.ToInt64 trueFlag}."
+ // The example displays the following output:
+ // False converts to 0.
+ // True converts to 1.
+ //
+
+let convertByte () =
+ //
+ let bytes =
+ [| Byte.MinValue; 14uy; 122uy; Byte.MaxValue |]
+
+ for byteValue in bytes do
+ let result = Convert.ToInt64 byteValue
+ printfn $"Converted the {byteValue.GetType().Name} value {byteValue} to the {result.GetType().Name} value {result}."
+ // The example displays the following output:
+ // Converted the Byte value 0 to the Int64 value 0.
+ // Converted the Byte value 14 to the Int64 value 14.
+ // Converted the Byte value 122 to the Int64 value 122.
+ // Converted the Byte value 255 to the Int64 value 255.
+ //
+
+let convertChar () =
+ //
+ let chars =
+ [| 'a'; 'z'; '\u0007'; '\u03FF'; '\u7FFF'; '\uFFFE' |]
+
+ for ch in chars do
+ try
+ let result = Convert.ToInt64 ch
+ printfn $"Converted the {ch.GetType().Name} value '{ch}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"Unable to convert u+{int ch:X4} to an Int32."
+ // The example displays the following output:
+ // Converted the Char value 'a' to the Int64 value 97.
+ // Converted the Char value 'z' to the Int64 value 122.
+ // Converted the Char value '' to the Int64 value 7.
+ // Converted the Char value 'Ͽ' to the Int64 value 1023.
+ // Converted the Char value '翿' to the Int64 value 32767.
+ // Converted the Char value '' to the Int64 value 65534.
+ //
+
+let convertDecimal () =
+ //
+ let values =
+ [| Decimal.MinValue; -1034.23m; -12m; 0m; 147m
+ 199.55m; 9214.16m; Decimal.MaxValue |]
+
+ for value in values do
+ try
+ let result = Convert.ToInt64 value
+ printfn $"Converted the {value.GetType().Name} value '{value}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"{value} is outside the range of the Int64 type."
+ // The example displays the following output:
+ // -79228162514264337593543950335 is outside the range of the Int64 type.
+ // Converted the Decimal value '-1034.23' to the Int64 value -1034.
+ // Converted the Decimal value '-12' to the Int64 value -12.
+ // Converted the Decimal value '0' to the Int64 value 0.
+ // Converted the Decimal value '147' to the Int64 value 147.
+ // Converted the Decimal value '199.55' to the Int64 value 200.
+ // Converted the Decimal value '9214.16' to the Int64 value 9214.
+ // 79228162514264337593543950335 is outside the range of the Int64 type.
+ //
+
+let convertDouble () =
+ //
+ let values =
+ [| Double.MinValue; -1.38e10; -1023.299; -12.98
+ 0; 9.113e-16; 103.919; 17834.191; Double.MaxValue |]
+
+ for value in values do
+ try
+ let result = Convert.ToInt64 value
+ printfn $"Converted the {value.GetType().Name} value '{value}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"{value} is outside the range of the Int64 type."
+ // -1.79769313486232E+308 is outside the range of the Int64 type.
+ // -13800000000 is outside the range of the Int64 type.
+ // Converted the Double value '-1023.299' to the Int64 value -1023.
+ // Converted the Double value '-12.98' to the Int64 value -13.
+ // Converted the Double value '0' to the Int64 value 0.
+ // Converted the Double value '9.113E-16' to the Int64 value 0.
+ // Converted the Double value '103.919' to the Int64 value 104.
+ // Converted the Double value '17834.191' to the Int64 value 17834.
+ // 1.79769313486232E+308 is outside the range of the Int64 type.
+ //
+
+let convertInt16 () =
+ //
+ let numbers =
+ [| Int16.MinValue; -1s; 0s; 121s; 340s; Int16.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToInt64 number
+ printfn $"Converted the {number.GetType().Name} value {number} to a {result.GetType().Name} value {result}."
+ // The example displays the following output:
+ // Converted the Int16 value -32768 to a Int64 value -32768.
+ // Converted the Int16 value -1 to a Int64 value -1.
+ // Converted the Int16 value 0 to a Int64 value 0.
+ // Converted the Int16 value 121 to a Int64 value 121.
+ // Converted the Int16 value 340 to a Int64 value 340.
+ // Converted the Int16 value 32767 to a Int64 value 32767.
+ //
+
+let convertInt32 () =
+ //
+ let numbers =
+ [| Int32.MinValue; -1; 0; 121; 340; Int32.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToInt64 number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"The {number.GetType().Name} value {number} is outside the range of the Int64 type."
+ // The example displays the following output:
+ // The Int64 value -9223372036854775808 is outside the range of the Int64 type.
+ // Converted the Int32 value -1 to the Int64 value -1.
+ // Converted the Int32 value 0 to the Int64 value 0.
+ // Converted the Int32 value 121 to the Int64 value 121.
+ // Converted the Int32 value 340 to the Int64 value 340.
+ // The Int64 value 9223372036854775807 is outside the range of the Int64 type.
+ //
+
+let convertObject () =
+ //
+ let values: obj[] =
+ [| true; -12; 163; 935; 'x'; DateTime(2009, 5, 12)
+ "104"; "103.0"; "-1"
+ "1.00e2"; "One"; 1.00e2; 16.3e42 |]
+
+ for value in values do
+ try
+ let result = Convert.ToInt64 value
+ printfn $"Converted the {value.GetType().Name} value {value} to the {result.GetType().Name} value {result}."
+ with
+ | :? OverflowException ->
+ printfn $"The {value.GetType().Name} value {value} is outside the range of the Int64 type."
+ | :? FormatException ->
+ printfn $"The {value.GetType().Name} value {value} is not in a recognizable format."
+ | :? InvalidCastException ->
+ printfn $"No conversion to an Int64 exists for the {value.GetType().Name} value {value}."
+ // The example displays the following output:
+ // Converted the Boolean value True to the Int64 value 1.
+ // Converted the Int32 value -12 to the Int64 value -12.
+ // Converted the Int32 value 163 to the Int64 value 163.
+ // Converted the Int32 value 935 to the Int64 value 935.
+ // Converted the Char value x to the Int64 value 120.
+ // No conversion to an Int64 exists for the DateTime value 5/12/2009 12:00:00 AM.
+ // Converted the String value 104 to the Int64 value 104.
+ // The String value 103.0 is not in a recognizable format.
+ // Converted the String value -1 to the Int64 value -1.
+ // The String value 1.00e2 is not in a recognizable format.
+ // The String value One is not in a recognizable format.
+ // Converted the Double value 100 to the Int64 value 100.
+ // The Double value 1.63E+43 is outside the range of the Int64 type.
+ //
+
+let convertSByte () =
+ //
+ let numbers =
+ [| SByte.MinValue; -1y; 0y; 10y; SByte.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToInt64 number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ // The example displays the following output:
+ // Converted the SByte value -128 to the Int64 value -128.
+ // Converted the SByte value -1 to the Int64 value -1.
+ // Converted the SByte value 0 to the Int64 value 0.
+ // Converted the SByte value 10 to the Int64 value 10.
+ // Converted the SByte value 127 to the Int64 value 127.
+ //
+
+let convertSingle () =
+ //
+ let values =
+ [| Single.MinValue; -1.38e10f; -1023.299f; -12.98f
+ 0f; 9.113e-16f; 103.919f; 17834.191f; Single.MaxValue |]
+
+ for value in values do
+ try
+ let result = Convert.ToInt64 value
+ printfn $"Converted the {value.GetType().Name} value {value} to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"{value} is outside the range of the Int64 type."
+ // The example displays the following output:
+ // -3.40282346638529E+38 is outside the range of the Int64 type.
+ // -13799999488 is outside the range of the Int64 type.
+ // Converted the Double value -1023.29901123047 to the Int64 value -1023.
+ // Converted the Double value -12.9799995422363 to the Int64 value -13.
+ // Converted the Double value 0 to the Int64 value 0.
+ // Converted the Double value 9.11299983940444E-16 to the Int64 value 0.
+ // Converted the Double value 103.918998718262 to the Int64 value 104.
+ // Converted the Double value 17834.19140625 to the Int64 value 17834.
+ // 3.40282346638529E+38 is outside the range of the Int64 type.
+ //
+
+let convertString () =
+ //
+ let values =
+ [| "One"; "1.34e28"; "-26.87"; "-18"; "-6.00"
+ " 0"; "137"; "1601.9"; string Int32.MaxValue |]
+
+ for value in values do
+ try
+ let result = Convert.ToInt64 value
+ printfn $"Converted the {value.GetType().Name} value {value} to the {result.GetType().Name} value {result}."
+ with
+ | :? OverflowException ->
+ printfn $"{value} is outside the range of the Int64 type."
+ | :? FormatException ->
+ printfn $"The {value.GetType().Name} value '{value}' is not in a recognizable format."
+ // The example displays the following output:
+ // The String value 'One' is not in a recognizable format.
+ // The String value '1.34e28' is not in a recognizable format.
+ // The String value '-26.87' is not in a recognizable format.
+ // Converted the String value '-18' to the Int64 value -18.
+ // The String value '-6.00' is not in a recognizable format.
+ // Converted the String value ' 0' to the Int64 value 0.
+ // Converted the String value '137' to the Int64 value 137.
+ // The String value '1601.9' is not in a recognizable format.
+ // Converted the String value '2147483647' to the Int64 value 2147483647.
+ //
+
+let convertUInt16 () =
+ //
+ let numbers =
+ [| UInt16.MinValue; 121us; 340us; UInt16.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToInt64 number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"The {number.GetType().Name} value {number} is outside the range of the Int64 type."
+ // The example displays the following output:
+ // Converted the UInt16 value 0 to the Int64 value 0.
+ // Converted the UInt16 value 121 to the Int64 value 121.
+ // Converted the UInt16 value 340 to the Int64 value 340.
+ // Converted the UInt16 value 65535 to the Int64 value 65535.
+ //
+
+let convertUInt32 () =
+ //
+ let numbers =
+ [| UInt32.MinValue; 121u; 340u; UInt32.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToInt64 number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"The {number.GetType().Name} value {number} is outside the range of the Int64 type."
+ // The example displays the following output:
+ // Converted the UInt32 value 0 to the Int64 value 0.
+ // Converted the UInt32 value 121 to the Int64 value 121.
+ // Converted the UInt32 value 340 to the Int64 value 340.
+ // The UInt32 value 4294967295 is outside the range of the Int64 type.
+ //
+
+let convertUInt64 () =
+ //
+ let numbers =
+ [| UInt64.MinValue; 121uL; 340uL; UInt64.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToInt64 number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"The {number.GetType().Name} value {number} is outside the range of the Int64 type."
+ // The example displays the following output:
+ // Converted the UInt64 value 0 to a Int32 value 0.
+ // Converted the UInt64 value 121 to a Int32 value 121.
+ // Converted the UInt64 value 340 to a Int32 value 340.
+ // The UInt64 value 18446744073709551615 is outside the range of the Int64 type.
+ //
+
+convertBoolean ()
+printfn "-----"
+convertByte ()
+printfn "-----"
+convertChar ()
+printfn "-----"
+convertDecimal ()
+printfn "-----"
+convertDouble ()
+printfn "-----"
+convertInt16 ()
+printfn "-----"
+convertInt32 ()
+printfn "-----"
+convertObject ()
+printfn "-----"
+convertSByte ()
+printfn "-----"
+convertSingle ()
+printfn "----"
+convertString ()
+printfn "-----"
+convertUInt16 ()
+printfn "-----"
+convertUInt32 ()
+printfn "-----"
+convertUInt64 ()
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToInt64/toint64_2.fs b/snippets/fsharp/System/Convert/ToInt64/toint64_2.fs
new file mode 100644
index 00000000000..a30944f8fa2
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToInt64/toint64_2.fs
@@ -0,0 +1,28 @@
+module toint64_2
+
+//
+open System
+
+let hexStrings =
+ [| "8000000000000000"; "0FFFFFFFFFFFFFFF"
+ "f0000000000001000"; "00A30"; "D"; "-13"; "GAD" |]
+for hexString in hexStrings do
+ try
+ let number = Convert.ToInt64(hexString, 16)
+ printfn $"Converted '{hexString}' to {number:N0}."
+ with
+ | :? FormatException ->
+ printfn $"'{hexString}' is not in the correct format for a hexadecimal number."
+ | :? OverflowException ->
+ printfn $"'{hexString}' is outside the range of an Int64."
+ | :? ArgumentException ->
+ printfn $"'{hexString}' is invalid in base 16."
+// The example displays the following output:
+// Converted '8000000000000000' to -9,223,372,036,854,775,808.
+// Converted '0FFFFFFFFFFFFFFF' to 1,152,921,504,606,846,975.
+// 'f0000000000001000' is outside the range of an Int64.
+// Converted '00A30' to 2,608.
+// Converted 'D' to 13.
+// '-13' is invalid in base 16.
+// 'GAD' is not in the correct format for a hexadecimal number.
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToInt64/toint64_3.fs b/snippets/fsharp/System/Convert/ToInt64/toint64_3.fs
new file mode 100644
index 00000000000..4a31149cbde
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToInt64/toint64_3.fs
@@ -0,0 +1,63 @@
+module toint64_3
+
+//
+open System
+open System.Globalization
+
+// Create a NumberFormatInfo object and set the properties that
+// affect conversions using Convert.ToInt64(String, IFormatProvider).
+let customProvider = NumberFormatInfo()
+customProvider.NegativeSign <- "neg "
+customProvider.PositiveSign <- "pos "
+
+// Create an array of providers with the custom provider and the
+// NumberFormatInfo object for the invariant culture.
+let providers =
+ [| customProvider; NumberFormatInfo.InvariantInfo |]
+
+// Define an array of strings to parse.
+let numericStrings =
+ [| "123456789"; "+123456789"; "pos 123456789"
+ "-123456789"; "neg 123456789"; "123456789."
+ "123,456,789"; "(123456789)"
+ "9223372036854775808"; "-9223372036854775809" |]
+
+for i = 0 to 2 do
+ let provider = providers[i]
+ printfn $"""{if i = 0 then "Custom Provider:" else "Invariant Culture:"}"""
+ for numericString in numericStrings do
+ printf $" {numericString,-22} --> "
+ try
+ printfn $"{Convert.ToInt32(numericString, provider),22}"
+ with
+ | :? FormatException ->
+ printfn "%22s" "Unrecognized Format"
+ | :? OverflowException ->
+ printfn "%22s" "Overflow"
+ printfn ""
+
+// The example displays the following output:
+// Custom Provider:
+// 123456789 --> 123456789
+// +123456789 --> Unrecognized Format
+// pos 123456789 --> 123456789
+// -123456789 --> Unrecognized Format
+// neg 123456789 --> -123456789
+// 123456789. --> Unrecognized Format
+// 123,456,789 --> Unrecognized Format
+// (123456789) --> Unrecognized Format
+// 9223372036854775808 --> Overflow
+// -9223372036854775809 --> Unrecognized Format
+//
+// Invariant Culture:
+// 123456789 --> 123456789
+// +123456789 --> 123456789
+// pos 123456789 --> Unrecognized Format
+// -123456789 --> -123456789
+// neg 123456789 --> Unrecognized Format
+// 123456789. --> Unrecognized Format
+// 123,456,789 --> Unrecognized Format
+// (123456789) --> Unrecognized Format
+// 9223372036854775808 --> Overflow
+// -9223372036854775809 --> Overflow
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToSByte/fs.fsproj b/snippets/fsharp/System/Convert/ToSByte/fs.fsproj
new file mode 100644
index 00000000000..0c3705ec469
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToSByte/fs.fsproj
@@ -0,0 +1,11 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToSByte/tosbyte1.fs b/snippets/fsharp/System/Convert/ToSByte/tosbyte1.fs
new file mode 100644
index 00000000000..018bf7d0db2
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToSByte/tosbyte1.fs
@@ -0,0 +1,320 @@
+module tosbyte1
+
+open System
+
+let convertBoolean () =
+ //
+ let falseFlag = false
+ let trueFlag = true
+
+ printfn $"{falseFlag} converts to {Convert.ToSByte falseFlag}."
+ printfn $"{trueFlag} converts to {Convert.ToSByte trueFlag}."
+ // The example displays the following output:
+ // False converts to 0.
+ // True converts to 1.
+ //
+
+let convertByte () =
+ //
+ let bytes =
+ [| Byte.MinValue; 14uy; 122uy; Byte.MaxValue |]
+
+ for byteValue in bytes do
+ let result = Convert.ToSByte byteValue
+ printfn $"Converted the {byteValue.GetType().Name} value {byteValue} to the {result.GetType().Name} value {result}."
+ // The example displays the following output:
+ // Converted the Byte value 0 to the SByte value 0.
+ // Converted the Byte value 14 to the SByte value 14.
+ // Converted the Byte value 122 to the SByte value 122.
+ // Converted the Byte value 255 to the SByte value 255.
+ //
+
+let convertChar () =
+ //
+ let chars =
+ [| 'a'; 'z'; '\u0007'; '\u03FF'; '\u7FFF'; '\uFFFE' |]
+
+ for ch in chars do
+ try
+ let result = Convert.ToSByte ch
+ printfn $"Converted the {ch.GetType().Name} value '{ch}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"Unable to convert u+{int ch:X4} to an Int32."
+ // The example displays the following output:
+ // Converted the Char value 'a' to the SByte value 97.
+ // Converted the Char value 'z' to the SByte value 122.
+ // Converted the Char value '' to the SByte value 7.
+ // Converted the Char value 'Ͽ' to the SByte value 1023.
+ // Converted the Char value '翿' to the SByte value 32767.
+ // Converted the Char value '' to the SByte value 65534.
+ //
+
+let convertDecimal () =
+ //
+ let values =
+ [| Decimal.MinValue; -1034.23m; -12m; 0m; 147m
+ 199.55m; 9214.16m; Decimal.MaxValue |]
+
+ for value in values do
+ try
+ let result = Convert.ToSByte value
+ printfn $"Converted the {value.GetType().Name} value '{value}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"{value} is outside the range of the SByte type."
+ // The example displays the following output:
+ // -79228162514264337593543950335 is outside the range of the SByte type.
+ // Converted the Decimal value '-1034.23' to the SByte value -1034.
+ // Converted the Decimal value '-12' to the SByte value -12.
+ // Converted the Decimal value '0' to the SByte value 0.
+ // Converted the Decimal value '147' to the SByte value 147.
+ // Converted the Decimal value '199.55' to the SByte value 200.
+ // Converted the Decimal value '9214.16' to the SByte value 9214.
+ // 79228162514264337593543950335 is outside the range of the SByte type.
+ //
+
+let convertDouble () =
+ //
+ let values =
+ [| Double.MinValue; -1.38e10; -1023.299; -12.98
+ 0; 9.113e-16; 103.919; 17834.191; Double.MaxValue |]
+
+ for value in values do
+ try
+ let result = Convert.ToSByte value
+ printfn $"Converted the {value.GetType().Name} value '{value}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"{value} is outside the range of the SByte type."
+ // -1.79769313486232E+308 is outside the range of the SByte type.
+ // -13800000000 is outside the range of the SByte type.
+ // Converted the Double value '-1023.299' to the SByte value -1023.
+ // Converted the Double value '-12.98' to the SByte value -13.
+ // Converted the Double value '0' to the SByte value 0.
+ // Converted the Double value '9.113E-16' to the SByte value 0.
+ // Converted the Double value '103.919' to the SByte value 104.
+ // Converted the Double value '17834.191' to the SByte value 17834.
+ // 1.79769313486232E+308 is outside the range of the SByte type.
+ //
+
+let convertInt16 () =
+ //
+ let numbers =
+ [| Int16.MinValue; -1s; 0s; 121s; 340s; Int16.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToSByte number
+ printfn $"Converted the {number.GetType().Name} value {number} to a {result.GetType().Name} value {result}."
+ // The example displays the following output:
+ // Converted the Int16 value -32768 to a Int64 value -32768.
+ // Converted the Int16 value -1 to a Int64 value -1.
+ // Converted the Int16 value 0 to a Int64 value 0.
+ // Converted the Int16 value 121 to a Int64 value 121.
+ // Converted the Int16 value 340 to a Int64 value 340.
+ // Converted the Int16 value 32767 to a Int64 value 32767.
+ //
+
+let convertInt32 () =
+ //
+ let numbers =
+ [| Int32.MinValue; -1; 0; 121; 340; Int32.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToSByte number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"The {number.GetType().Name} value {number} is outside the range of the SByte type."
+ // The example displays the following output:
+ // The Int32 value -2147483647 is outside the range of the SByte type.
+ // Converted the Int32 value -1 to the SByte value -1.
+ // Converted the Int32 value 0 to the SByte value 0.
+ // Converted the Int32 value 121 to the SByte value 121.
+ // Converted the Int32 value 340 to the SByte value 340.
+ // The Int32 value 2147483647 is outside the range of the SByte type.
+ //
+
+let convertInt64 () =
+ //
+ let numbers =
+ [| Int64.MinValue; -1L; 0L; 121L; 340L; Int64.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToSByte number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"The {number.GetType().Name} value {number} is outside the range of the SByte type."
+ // The example displays the following output:
+ // The Int64 value -9223372036854775808 is outside the range of the SByte type.
+ // Converted the Int64 value -1 to the SByte value -1.
+ // Converted the Int64 value 0 to the SByte value 0.
+ // Converted the Int64 value 121 to the SByte value 121.
+ // Converted the Int64 value 340 to the SByte value 340.
+ // The Int64 value 9223372036854775807 is outside the range of the SByte type.
+ //
+
+let convertObject () =
+ //
+ let values: obj[] =
+ [| true; -12; 163; 935; 'x'; DateTime(2009, 5, 12)
+ "104"; "103.0"; "-1"
+ "1.00e2"; "One"; 1.00e2; 16.3e42 |]
+
+ for value in values do
+ try
+ let result = Convert.ToSByte value
+ printfn $"Converted the {value.GetType().Name} value {value} to the {result.GetType().Name} value {result}."
+ with
+ | :? OverflowException ->
+ printfn $"The {value.GetType().Name} value {value} is outside the range of the SByte type."
+ | :? FormatException ->
+ printfn $"The {value.GetType().Name} value {value} is not in a recognizable format."
+ | :? InvalidCastException ->
+ printfn $"No conversion to an SByte exists for the {value.GetType().Name} value {value}."
+ // The example displays the following output:
+ // Converted the Boolean value True to the SByte value 1.
+ // Converted the Int32 value -12 to the SByte value -12.
+ // Converted the Int32 value 163 to the SByte value 163.
+ // Converted the Int32 value 935 to the SByte value 935.
+ // Converted the Char value x to the SByte value 120.
+ // No conversion to an SByte exists for the DateTime value 5/12/2009 12:00:00 AM.
+ // Converted the String value 104 to the SByte value 104.
+ // The String value 103.0 is not in a recognizable format.
+ // Converted the String value -1 to the SByte value -1.
+ // The String value 1.00e2 is not in a recognizable format.
+ // The String value One is not in a recognizable format.
+ // Converted the Double value 100 to the SByte value 100.
+ // The Double value 1.63E+43 is outside the range of the SByte type.
+ //
+
+let convertSingle () =
+ //
+ let values =
+ [| Single.MinValue; -1.38e10f; -1023.299f; -12.98f
+ 0f; 9.113e-16f; 103.919f; 17834.191f; Single.MaxValue |]
+
+ for value in values do
+ try
+ let result = Convert.ToSByte value
+ printfn $"Converted the {value.GetType().Name} value {value} to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"{value} is outside the range of the SByte type."
+ // The example displays the following output:
+ // -3.40282346638529E+38 is outside the range of the SByte type.
+ // -13799999488 is outside the range of the SByte type.
+ // Converted the Double value -1023.29901123047 to the SByte value -1023.
+ // Converted the Double value -12.9799995422363 to the SByte value -13.
+ // Converted the Double value 0 to the SByte value 0.
+ // Converted the Double value 9.11299983940444E-16 to the SByte value 0.
+ // Converted the Double value 103.918998718262 to the SByte value 104.
+ // Converted the Double value 17834.19140625 to the SByte value 17834.
+ // 3.40282346638529E+38 is outside the range of the SByte type.
+ //
+
+let convertString () =
+ //
+ let values =
+ [| "One"; "1.34e28"; "-26.87"; "-18"; "-6.00"
+ " 0"; "137"; "1601.9"; string Int32.MaxValue |]
+
+ for value in values do
+ try
+ let result = Convert.ToSByte value
+ printfn $"Converted the {value.GetType().Name} value {value} to the {result.GetType().Name} value {result}."
+ with
+ | :? OverflowException ->
+ printfn $"{value} is outside the range of the SByte type."
+ | :? FormatException ->
+ printfn $"The {value.GetType().Name} value '{value}' is not in a recognizable format."
+ // The example displays the following output:
+ // The String value 'One' is not in a recognizable format.
+ // The String value '1.34e28' is not in a recognizable format.
+ // The String value '-26.87' is not in a recognizable format.
+ // Converted the String value '-18' to the SByte value -18.
+ // The String value '-6.00' is not in a recognizable format.
+ // Converted the String value ' 0' to the SByte value 0.
+ // Converted the String value '137' to the SByte value 137.
+ // The String value '1601.9' is not in a recognizable format.
+ // Converted the String value '2147483647' to the SByte value 2147483647.
+ //
+
+let convertUInt16 () =
+ //
+ let numbers =
+ [| UInt16.MinValue; 121us; 340us; UInt16.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToSByte number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"The {number.GetType().Name} value {number} is outside the range of the SByte type."
+ // The example displays the following output:
+ // Converted the UInt16 value 0 to the SByte value 0.
+ // Converted the UInt16 value 121 to the SByte value 121.
+ // Converted the UInt16 value 340 to the SByte value 340.
+ // Converted the UInt16 value 65535 to the SByte value 65535.
+ //
+
+let convertUInt32 () =
+ //
+ let numbers =
+ [| UInt32.MinValue; 121u; 340u; UInt32.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToSByte number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"The {number.GetType().Name} value {number} is outside the range of the SByte type."
+ // The example displays the following output:
+ // Converted the UInt32 value 0 to the SByte value 0.
+ // Converted the UInt32 value 121 to the SByte value 121.
+ // Converted the UInt32 value 340 to the SByte value 340.
+ // The UInt32 value 4294967295 is outside the range of the SByte type.
+ //
+
+let convertUInt64 () =
+ //
+ let numbers =
+ [| UInt64.MinValue; 121uL; 340uL; UInt64.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToSByte number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"The {number.GetType().Name} value {number} is outside the range of the SByte type."
+ // The example displays the following output:
+ // Converted the UInt64 value 0 to a Int32 value 0.
+ // Converted the UInt64 value 121 to a Int32 value 121.
+ // Converted the UInt64 value 340 to a Int32 value 340.
+ // The UInt64 value 18446744073709551615 is outside the range of the SByte type.
+ //
+
+convertBoolean ()
+printfn "-----"
+convertByte ()
+printfn "-----"
+convertChar ()
+printfn "-----"
+convertDecimal ()
+printfn "-----"
+convertDouble ()
+printfn "-----"
+convertInt16 ()
+printfn "-----"
+convertInt32 ()
+printfn "-----"
+convertInt64 ()
+printfn "-----"
+convertObject ()
+printfn "-----"
+convertSingle ()
+printfn "----"
+convertString ()
+printfn "-----"
+convertUInt16 ()
+printfn "-----"
+convertUInt32 ()
+printfn "-----"
+convertUInt64 ()
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToSByte/tosbyte2.fs b/snippets/fsharp/System/Convert/ToSByte/tosbyte2.fs
new file mode 100644
index 00000000000..44f21cb7007
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToSByte/tosbyte2.fs
@@ -0,0 +1,195 @@
+module Tosbyte2
+
+//
+open System
+open System.Globalization
+
+type SignBit =
+ | Negative = -1
+ | Zero = 0
+ | Positive = 1
+
+[]
+type ByteString =
+ val mutable private byteString: string
+
+ val mutable Sign : SignBit
+
+ member this.Value
+ with get () = this.byteString
+ and set (value: string) =
+ if value.Trim().Length > 2 then
+ invalidArg "value" "The string representation of a byte cannot have more than two characters."
+ this.byteString <- value
+
+ // IConvertible implementations.
+ interface IConvertible with
+ member _.GetTypeCode() =
+ TypeCode.Object
+
+ member this.ToBoolean(provider: IFormatProvider) =
+ this.Sign <> SignBit.Zero
+
+ member this.ToByte(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ raise (OverflowException $"{Convert.ToSByte(this.byteString, 16)} is out of range of the Byte type.")
+ else
+ Byte.Parse(this.byteString, NumberStyles.HexNumber)
+
+ member this.ToChar(provider: IFormatProvider) =
+
+ if this.Sign = SignBit.Negative then
+ raise (OverflowException $"{Convert.ToSByte(this.byteString, 16)} is out of range of the Char type.")
+ else
+ let byteValue = Byte.Parse(this.byteString, NumberStyles.HexNumber)
+ Convert.ToChar byteValue
+
+ member _.ToDateTime(provider: IFormatProvider) =
+ raise (InvalidCastException "ByteString to DateTime conversion is not supported.")
+
+ member this.ToDecimal(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ SByte.Parse(this.byteString, NumberStyles.HexNumber)
+ |> Convert.ToDecimal
+ else
+ Byte.Parse(this.byteString, NumberStyles.HexNumber)
+ |> Convert.ToDecimal
+
+ member this.ToDouble(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ SByte.Parse(this.byteString, NumberStyles.HexNumber)
+ |> Convert.ToDouble
+ else
+ Byte.Parse(this.byteString, NumberStyles.HexNumber)
+ |> Convert.ToDouble
+
+ member this.ToInt16(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ SByte.Parse(this.byteString, NumberStyles.HexNumber)
+ |> Convert.ToInt16
+ else
+ Byte.Parse(this.byteString, NumberStyles.HexNumber)
+ |> Convert.ToInt16
+
+ member this.ToInt32(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ SByte.Parse(this.byteString, NumberStyles.HexNumber)
+ |> Convert.ToInt32
+ else
+ Byte.Parse(this.byteString, NumberStyles.HexNumber)
+ |> Convert.ToInt32
+
+ member this.ToInt64(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ SByte.Parse(this.byteString, NumberStyles.HexNumber)
+ |> Convert.ToInt64
+ else
+ Byte.Parse(this.byteString, NumberStyles.HexNumber)
+ |> Convert.ToInt64
+
+ member this.ToSByte(provider: IFormatProvider) =
+ try
+ SByte.Parse(this.byteString, NumberStyles.HexNumber)
+ with :? OverflowException as e ->
+ raise (OverflowException($"{Byte.Parse(this.byteString, NumberStyles.HexNumber)} is outside the range of the SByte type.", e) )
+
+ member this.ToSingle(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ SByte.Parse(this.byteString, NumberStyles.HexNumber)
+ |> Convert.ToSingle
+ else
+ Byte.Parse(this.byteString, NumberStyles.HexNumber)
+ |> Convert.ToSingle
+
+ member this.ToString(provider: IFormatProvider) =
+ "0x" + this.byteString
+
+ member this.ToType(conversionType: Type, provider: IFormatProvider) =
+ let this = this :> IConvertible
+ match Type.GetTypeCode conversionType with
+ | TypeCode.Boolean ->
+ this.ToBoolean null
+ | TypeCode.Byte ->
+ this.ToByte null
+ | TypeCode.Char ->
+ this.ToChar null
+ | TypeCode.DateTime ->
+ this.ToDateTime null
+ | TypeCode.Decimal ->
+ this.ToDecimal null
+ | TypeCode.Double ->
+ this.ToDouble null
+ | TypeCode.Int16 ->
+ this.ToInt16 null
+ | TypeCode.Int32 ->
+ this.ToInt32 null
+ | TypeCode.Int64 ->
+ this.ToInt64 null
+ | TypeCode.Object ->
+ if typeof.Equals conversionType then
+ this
+ else
+ raise (InvalidCastException $"Conversion to a {conversionType.Name} is not supported.")
+ | TypeCode.SByte ->
+ this.ToSByte null
+ | TypeCode.Single ->
+ this.ToSingle null
+ | TypeCode.String ->
+ this.ToString null
+ | TypeCode.UInt16 ->
+ this.ToUInt16 null
+ | TypeCode.UInt32 ->
+ this.ToUInt32 null
+ | TypeCode.UInt64 ->
+ this.ToUInt64 null
+ | _ ->
+ raise (InvalidCastException $"Conversion to {conversionType.Name} is not supported.")
+
+ member this.ToUInt16(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ raise (OverflowException $"{SByte.Parse(this.byteString, NumberStyles.HexNumber)} is outside the range of the UInt16 type." )
+ else
+ Byte.Parse(this.byteString, NumberStyles.HexNumber)
+ |> Convert.ToUInt16
+
+ member this.ToUInt32(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ raise (OverflowException $"{SByte.Parse(this.byteString, NumberStyles.HexNumber)} is outside the range of the UInt32 type.")
+ else
+ Byte.Parse(this.byteString, NumberStyles.HexNumber)
+ |> Convert.ToUInt32
+
+ member this.ToUInt64(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ raise (OverflowException $"{SByte.Parse(this.byteString, NumberStyles.HexNumber)} is outside the range of the UInt32 type.")
+ else
+ Byte.Parse(this.byteString, NumberStyles.HexNumber)
+ |> Convert.ToUInt64
+//
+
+//
+let positiveByte = 120y
+let negativeByte = -101y
+
+let mutable positiveString = ByteString()
+positiveString.Sign <- sign positiveByte |> enum
+positiveString.Value <- positiveByte.ToString "X2"
+
+let mutable negativeString = ByteString()
+negativeString.Sign <- sign negativeByte |> enum
+negativeString.Value <- negativeByte.ToString "X2"
+
+try
+ printfn $"'{positiveString.Value}' converts to {Convert.ToSByte positiveString}."
+with :? OverflowException ->
+ printfn $"0x{positiveString.Value} is outside the range of the Byte type."
+
+try
+ printfn $"'{negativeString.Value}' converts to {Convert.ToSByte negativeString}."
+with :? OverflowException ->
+ printfn $"0x{negativeString.Value} is outside the range of the Byte type."
+
+// The example displays the following output:
+// '78' converts to 120.
+// '9B' converts to -101.
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToSByte/tosbyte3.fs b/snippets/fsharp/System/Convert/ToSByte/tosbyte3.fs
new file mode 100644
index 00000000000..14eb2524dc0
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToSByte/tosbyte3.fs
@@ -0,0 +1,61 @@
+module tosbyte3
+
+//
+open System
+
+let baseValues =
+ [| 2; 8; 16 |]
+let values =
+ [| "FF"; "81"; "03"; "11"; "8F"; "01"; "1C"; "111"; "123"; "18A" |]
+
+// Convert to each supported base.
+for baseValue in baseValues do
+ printfn $"Converting strings in base {baseValue}:"
+ for value in values do
+ printf $""" '{value + "'",-5} --> """
+ try
+ printfn $"{Convert.ToSByte(value, baseValue)}"
+ with
+ | :? FormatException ->
+ printfn "Bad Format"
+ | :? OverflowException ->
+ printfn "Out of Range"
+ printfn ""
+
+// The example displays the following output:
+// Converting strings in base 2:
+// 'FF' --> Bad Format
+// '81' --> Bad Format
+// '03' --> Bad Format
+// '11' --> 3
+// '8F' --> Bad Format
+// '01' --> 1
+// '1C' --> Bad Format
+// '111' --> 7
+// '123' --> Bad Format
+// '18A' --> Bad Format
+//
+// Converting strings in base 8:
+// 'FF' --> Bad Format
+// '81' --> Bad Format
+// '03' --> 3
+// '11' --> 9
+// '8F' --> Bad Format
+// '01' --> 1
+// '1C' --> Bad Format
+// '111' --> 73
+// '123' --> 83
+// '18A' --> Bad Format
+//
+// Converting strings in base 16:
+// 'FF' --> -1
+// '81' --> -127
+// '03' --> 3
+// '11' --> 17
+// '8F' --> -113
+// '01' --> 1
+// '1C' --> 28
+// '111' --> Out of Range
+// '123' --> Out of Range
+// '18A' --> Out of Range
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToSingle/fs.fsproj b/snippets/fsharp/System/Convert/ToSingle/fs.fsproj
new file mode 100644
index 00000000000..46d215fbc28
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToSingle/fs.fsproj
@@ -0,0 +1,11 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToSingle/tosingle1.fs b/snippets/fsharp/System/Convert/ToSingle/tosingle1.fs
new file mode 100644
index 00000000000..93fa66e18cb
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToSingle/tosingle1.fs
@@ -0,0 +1,255 @@
+module tosingle1
+
+open System
+
+let convertBoolean () =
+ //
+ let flags = [| true; false |]
+
+ for flag in flags do
+ let result = Convert.ToSingle flag
+ printfn $"Converted {flag} to {result}."
+ // The example displays the following output:
+ // Converted True to 1.
+ // Converted False to 0.
+ //
+
+let convertByte () =
+ //
+ let numbers = [| Byte.MinValue; 10uy; 100uy; Byte.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToSingle number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ // The example displays the following output:
+ // Converted the Byte value 0 to the Single value 0.
+ // Converted the Byte value 10 to the Single value 10.
+ // Converted the Byte value 100 to the Single value 100.
+ // Converted the Byte value 255 to the Single value 255.
+ //
+
+let convertDecimal () =
+ //
+ let values =
+ [| Decimal.MinValue; -1034.23m; -12m; 0m; 147m; 199.55m; 9214.16m; Decimal.MaxValue |]
+
+ for value in values do
+ let result = Convert.ToSingle value
+ printfn $"Converted the {value.GetType().Name} value {value} to the {result.GetType().Name} value {result}."
+ // The example displays the following output:
+ // Converted the Decimal value '-79228162514264337593543950335' to the Single value -7.9228163E+28.
+ // Converted the Decimal value '-1034.23' to the Single value -1034.23.
+ // Converted the Decimal value '-12' to the Single value -12.
+ // Converted the Decimal value '0' to the Single value 0.
+ // Converted the Decimal value '147' to the Single value 147.
+ // Converted the Decimal value '199.55' to the Single value 199.55.
+ // Converted the Decimal value '9214.16' to the Single value 9214.16.
+ // Converted the Decimal value '79228162514264337593543950335' to the Single value 7.9228163E+28.
+ //
+
+let convertDouble () =
+ //
+ let values =
+ [| Double.MinValue; -1.38e10; -1023.299; -12.98; 0; 9.113e-16; 103.919; 17834.191; Double.MaxValue |]
+
+ for value in values do
+ let result = Convert.ToSingle value
+ printfn $"Converted the {value.GetType().Name} value {value} to the {result.GetType().Name} value {result}."
+ // The example displays the following output:
+ // Converted the Double value '-1.79769313486232E+308' to the Single value -Infinity.
+ // Converted the Double value '-13800000000' to the Single value -1.38E+10.
+ // Converted the Double value '-1023.299' to the Single value -1023.299.
+ // Converted the Double value '-12.98' to the Single value -12.98.
+ // Converted the Double value '0' to the Single value 0.
+ // Converted the Double value '9.113E-16' to the Single value 9.113E-16.
+ // Converted the Double value '103.919' to the Single value 103.919.
+ // Converted the Double value '17834.191' to the Single value 17834.19.
+ // Converted the Double value '1.79769313486232E+308' to the Single value Infinity.
+ //
+
+let convertInt16 () =
+ //
+ let numbers =
+ [| Int16.MinValue; -1032s; 0s; 192s; Int16.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToSingle number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ // The example displays the following output:
+ // Converted the Int16 value '-32768' to the Single value -32768.
+ // Converted the Int16 value '-1032' to the Single value -1032.
+ // Converted the Int16 value '0' to the Single value 0.
+ // Converted the Int16 value '192' to the Single value 192.
+ // Converted the Int16 value '32767' to the Single value 32767.
+ //
+
+let convertInt32 () =
+ //
+ let numbers =
+ [| Int32.MinValue; -1000; 0; 1000; Int32.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToSingle number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ // The example displays the following output:
+ // Converted the Int32 value '-2147483648' to the Single value -2.147484E+09.
+ // Converted the Int32 value '-1000' to the Single value -1000.
+ // Converted the Int32 value '0' to the Single value 0.
+ // Converted the Int32 value '1000' to the Single value 1000.
+ // Converted the Int32 value '2147483647' to the Single value 2.147484E+09.
+ //
+
+let convertInt64 () =
+ //
+ let numbers =
+ [| Int64.MinValue; -903; 0; 172; Int64.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToSingle number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ // The example displays the following output:
+ // Converted the Int64 value '-9223372036854775808' to the Single value -9.223372E+18.
+ // Converted the Int64 value '-903' to the Single value -903.
+ // Converted the Int64 value '0' to the Single value 0.
+ // Converted the Int64 value '172' to the Single value 172.
+ // Converted the Int64 value '9223372036854775807' to the Single value 9.223372E+18.
+ //
+
+let convertObject () =
+ //
+ let values: obj[] =
+ [| true; 'a'; 123; 1.764e32; "9.78"; "1e-02"; 1.67e03; "A100"; "1,033.67"; DateTime.Now; Decimal.MaxValue |]
+
+ for value in values do
+ try
+ let result = Convert.ToSingle value
+ printfn $"Converted the {value.GetType().Name} value {value} to the {result.GetType().Name} value {result}."
+ with
+ | :? FormatException ->
+ printfn $"The {value.GetType().Name} value {value} is not recognized as a valid Single value."
+ | :? OverflowException ->
+ printfn $"The {value.GetType().Name} value {value} is outside the range of the Single type."
+ | :? InvalidCastException ->
+ printfn $"Conversion of the {value.GetType().Name} value {value} to a Single is not supported."
+ // The example displays the following output:
+ // Converted the Boolean value 'True' to the Single value 1.
+ // Conversion of the Char value a to a Single is not supported.
+ // Converted the Int32 value '123' to the Single value 123.
+ // Converted the Double value '1.764E+32' to the Single value 1.764E+32.
+ // Converted the String value '9.78' to the Single value 9.78.
+ // Converted the String value '1e-02' to the Single value 0.01.
+ // Converted the Double value '1670' to the Single value 1670.
+ // The String value A100 is not recognized as a valid Single value.
+ // Converted the String value '1,033.67' to the Single value 1033.67.
+ // Conversion of the DateTime value 11/7/2008 08:02:35 AM to a Single is not supported.
+ // Converted the Decimal value '79228162514264337593543950335' to the Single value 7.922816E+28.
+ //
+
+let convertSByte () =
+ //
+ let numbers = [| SByte.MinValue; -23y; 0y; 17y; SByte.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToSingle number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ // The example displays the following output:
+ // Converted the SByte value '-128' to the Single value -128.
+ // Converted the SByte value '-23' to the Single value -23.
+ // Converted the SByte value '0' to the Single value 0.
+ // Converted the SByte value '17' to the Single value 17.
+ // Converted the SByte value '127' to the Single value 127.
+ //
+
+let convertString () =
+ //
+ let values =
+ [| "-1,035.77219"; "1AFF"; "1e-35"; "1.63f"; "1,635,592,999,999,999,999,999,999"
+ "-17.455"; "190.34001"; "1.29e325" |]
+
+ for value in values do
+ try
+ let result = Convert.ToSingle value
+ printfn $"Converted the {value.GetType().Name} value {value} to the {result.GetType().Name} value {result}."
+ with
+ | :? FormatException ->
+ printfn $"Unable to convert '{value}' to a Single."
+ | :? OverflowException ->
+ printfn $"'{value}' is outside the range of a Single."
+ // The example displays the following output:
+ // Converted the String value '-1,035.77219' to the Single value -1035.772.
+ // Unable to convert '1AFF' to a Single.
+ // Converted the String value '1e-35' to the Single value 1E-35.
+ // Unable to convert '1.63f' to a Single.
+ // Converted the String value '1,635,592,999,999,999,999,999,999' to the Single value 1.635593E+24.
+ // Converted the String value '-17.455' to the Single value -17.455.
+ // Converted the String value '190.34001' to the Single value 190.34.
+ // 1.29e325' is outside the range of a Single.
+ //
+
+let convertUInt16 () =
+ //
+ let numbers = [| UInt16.MinValue; 121us; 12345us; UInt16.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToSingle number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ // The example displays the following output:
+ // Converted the UInt16 value '0' to the Single value 0.
+ // Converted the UInt16 value '121' to the Single value 121.
+ // Converted the UInt16 value '12345' to the Single value 12345.
+ // Converted the UInt16 value '65535' to the Single value 65535.
+ //
+
+let convertUInt32 () =
+ //
+ let numbers = [| UInt32.MinValue; 121u; 12345u; UInt32.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToSingle number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ // The example displays the following output:
+ // Converted the UInt32 value '0' to the Single value 0.
+ // Converted the UInt32 value '121' to the Single value 121.
+ // Converted the UInt32 value '12345' to the Single value 12345.
+ // Converted the UInt32 value '4294967295' to the Single value 4.294967E+09.
+ //
+
+let convertUInt64 () =
+ //
+ let numbers = [| UInt64.MinValue; 121uL; 12345uL; UInt64.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToSingle number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ // The example displays the following output:
+ // Converted the UInt64 value '0' to the Single value 0.
+ // Converted the UInt64 value '121' to the Single value 121.
+ // Converted the UInt64 value '12345' to the Single value 12345.
+ // Converted the UInt64 value '18446744073709551615' to the Single value 1.844674E+19.
+ //
+
+convertBoolean()
+printfn "-----"
+convertByte ()
+printfn "-----"
+convertDecimal ()
+printfn "-----"
+convertDouble ()
+printfn "-----"
+convertInt16 ()
+printfn "-----"
+convertInt32 ()
+printfn "-----"
+convertInt64 ()
+printfn "-----"
+convertObject ()
+printfn "-----"
+convertSByte ()
+printfn "-----"
+convertString ()
+printfn "----"
+convertUInt16 ()
+printfn "-----"
+convertUInt32 ()
+printfn "------"
+convertUInt64 ()
diff --git a/snippets/fsharp/System/Convert/ToSingle/tosingle2.fs b/snippets/fsharp/System/Convert/ToSingle/tosingle2.fs
new file mode 100644
index 00000000000..ebd2cbdcf81
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToSingle/tosingle2.fs
@@ -0,0 +1,148 @@
+module tosingle2
+
+//
+open System
+
+type Temperature(temperature: float32) =
+ member _.Celsius =
+ temperature
+
+ member _.Kelvin =
+ temperature + 273.15f
+
+ member _.Fahrenheit =
+ MathF.Round(temperature * 9f / 5f + 32f, 2)
+
+ override _.ToString() =
+ $"{temperature:N2} °C"
+
+ // IConvertible implementations.
+ interface IConvertible with
+
+ member _.GetTypeCode() =
+ TypeCode.Object
+
+ member _.ToBoolean(provider: IFormatProvider) =
+ temperature <> 0f
+
+ member _.ToByte(provider: IFormatProvider) =
+ if temperature < float32 Byte.MinValue || temperature > float32 Byte.MaxValue then
+ raise (OverflowException $"{temperature} is out of range of the Byte type.")
+ else
+ Convert.ToByte temperature
+
+ member _.ToChar(provider: IFormatProvider) =
+ raise (InvalidCastException "Temperature to Char conversion is not supported.")
+
+ member _.ToDateTime(provider: IFormatProvider) =
+ raise (InvalidCastException "Temperature to DateTime conversion is not supported.")
+
+ member _.ToDecimal(provider: IFormatProvider) =
+ Convert.ToDecimal temperature
+
+ member _.ToDouble(provider: IFormatProvider) =
+ Convert.ToDouble temperature
+
+ member _.ToInt16(provider: IFormatProvider) =
+ if temperature < float32 Int16.MinValue || temperature > float32 Int16.MaxValue then
+ raise (OverflowException $"{temperature} is out of range of the Int16 type.")
+ else
+ Convert.ToInt16 temperature
+
+ member _.ToInt32(provider: IFormatProvider) =
+ if temperature < float32 Int32.MinValue || temperature > float32 Int32.MaxValue then
+ raise (OverflowException $"{temperature} is out of range of the Int32 type.")
+ else
+ Convert.ToInt32 temperature
+
+ member _.ToInt64(provider: IFormatProvider) =
+ if float32 temperature < float32 Int64.MinValue || temperature > float32 Int64.MaxValue then
+ raise (OverflowException $"{temperature} is out of range of the Int64 type.")
+ else
+ Convert.ToInt64 temperature
+
+ member _.ToSByte(provider: IFormatProvider) =
+ if temperature < float32 SByte.MinValue || temperature > float32 SByte.MaxValue then
+ raise (OverflowException $"{temperature} is out of range of the SByte type.")
+ else
+ Convert.ToSByte temperature
+
+ member _.ToSingle(provider: IFormatProvider) =
+ temperature
+
+ override _.ToString(provider: IFormatProvider) =
+ temperature.ToString("N2", provider) + " °C"
+
+ member this.ToType(conversionType: Type, provider: IFormatProvider) =
+ let this = this :> IConvertible
+ match Type.GetTypeCode conversionType with
+ | TypeCode.Boolean ->
+ this.ToBoolean null
+ | TypeCode.Byte ->
+ this.ToByte null
+ | TypeCode.Char ->
+ this.ToChar null
+ | TypeCode.DateTime ->
+ this.ToDateTime null
+ | TypeCode.Decimal ->
+ this.ToDecimal null
+ | TypeCode.Double ->
+ this.ToDouble null
+ | TypeCode.Int16 ->
+ this.ToInt16 null
+ | TypeCode.Int32 ->
+ this.ToInt32 null
+ | TypeCode.Int64 ->
+ this.ToInt64 null
+ | TypeCode.Object ->
+ if typeof.Equals conversionType then
+ this
+ else
+ raise (InvalidCastException $"Conversion to a {conversionType.Name} is not supported.")
+ | TypeCode.SByte ->
+ this.ToSByte null
+ | TypeCode.Single ->
+ this.ToSingle null
+ | TypeCode.String ->
+ this.ToString provider
+ | TypeCode.UInt16 ->
+ this.ToUInt16 null
+ | TypeCode.UInt32 ->
+ this.ToUInt32 null
+ | TypeCode.UInt64 ->
+ this.ToUInt64 null
+ | _ ->
+ raise (InvalidCastException $"Conversion to {conversionType.Name} is not supported.")
+
+ member _.ToUInt16(provider: IFormatProvider) =
+ if temperature < float32 UInt16.MinValue || temperature > float32 UInt16.MaxValue then
+ raise (OverflowException $"{temperature} is out of range of the UInt16 type.")
+ else
+ Convert.ToUInt16 temperature
+
+ member _.ToUInt32(provider: IFormatProvider) =
+ if temperature < float32 UInt32.MinValue || temperature > float32 UInt32.MaxValue then
+ raise (OverflowException $"{temperature} is out of range of the UInt32 type.")
+ else
+ Convert.ToUInt32 temperature
+
+ member _.ToUInt64(provider: IFormatProvider) =
+ if temperature < float32 UInt64.MinValue || temperature > float32 UInt64.MaxValue then
+ raise (OverflowException $"{temperature} is out of range of the UInt64 type.")
+ else
+ Convert.ToUInt64 temperature
+//
+
+//
+let cold = Temperature -40f
+let freezing = Temperature 0f
+let boiling = Temperature 100f
+
+printfn $"{Convert.ToInt32(cold, null)}"
+printfn $"{Convert.ToInt32(freezing, null)}"
+printfn $"{Convert.ToDouble(boiling, null)}"
+// The example dosplays the following output:
+// -40
+// 0
+// 100
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToSingle/tosingle3.fs b/snippets/fsharp/System/Convert/ToSingle/tosingle3.fs
new file mode 100644
index 00000000000..69410326936
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToSingle/tosingle3.fs
@@ -0,0 +1,51 @@
+module tosingle3
+
+//
+open System
+open System.Globalization
+
+let values =
+ [| "123456789"; "12345.6789"; "12 345,6789"
+ "123,456.789"; "123 456,789"; "123,456,789.0123"
+ "123 456 789,0123"; "1.235e12"; "1.03221e-05"
+ string Double.MaxValue |]
+let cultures =
+ [| CultureInfo "en-US"; CultureInfo "fr-FR" |]
+
+for culture in cultures do
+ printfn $"String -> Single Conversion Using the {culture.Name} Culture"
+ for value in values do
+ printf $"{value,22} -> "
+ try
+ printfn $"{Convert.ToSingle(value, culture)}"
+ with
+ | :? FormatException ->
+ printfn "FormatException"
+ | :? OverflowException ->
+ printfn "OverflowException"
+ printfn ""
+// The example displays the following output:
+// String -> Single Conversion Using the en-US Culture
+// 123456789 -> 1.234568E+08
+// 12345.6789 -> 12345.68
+// 12 345,6789 -> FormatException
+// 123,456.789 -> 123456.8
+// 123 456,789 -> FormatException
+// 123,456,789.0123 -> 1.234568E+08
+// 123 456 789,0123 -> FormatException
+// 1.235e12 -> 1.235E+12
+// 1.03221e-05 -> 1.03221E-05
+// 1.79769313486232E+308 -> Overflow
+//
+// String -> Single Conversion Using the fr-FR Culture
+// 123456789 -> 1.234568E+08
+// 12345.6789 -> FormatException
+// 12 345,6789 -> 12345.68
+// 123,456.789 -> FormatException
+// 123 456,789 -> 123456.8
+// 123,456,789.0123 -> FormatException
+// 123 456 789,0123 -> 1.234568E+08
+// 1.235e12 -> FormatException
+// 1.03221e-05 -> FormatException
+// 1.79769313486232E+308 -> FormatException
+//
diff --git a/snippets/fsharp/System/Convert/ToString/ToString.Byte1.fs b/snippets/fsharp/System/Convert/ToString/ToString.Byte1.fs
new file mode 100644
index 00000000000..44b7eb4e204
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToString/ToString.Byte1.fs
@@ -0,0 +1,18 @@
+module ToString.Byte1
+
+//
+open System
+
+let values =
+ [| Byte.MinValue; 12uy; 100uy; 179uy; Byte.MaxValue |]
+
+for value in values do
+ printfn $"{value,3} ({value.GetType().Name}) --> {Convert.ToString value}"
+
+// The example displays the following output:
+// 0 (Byte) --> 0
+// 12 (Byte) --> 12
+// 100 (Byte) --> 100
+// 179 (Byte) --> 179
+// 255 (Byte) --> 255
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToString/ToString_Bool1.fs b/snippets/fsharp/System/Convert/ToString/ToString_Bool1.fs
new file mode 100644
index 00000000000..3f2f571d4ed
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToString/ToString_Bool1.fs
@@ -0,0 +1,18 @@
+module ToString_Bool1
+
+open System
+
+//
+let falseFlag = false
+let trueFlag = true
+
+printfn $"{Convert.ToString falseFlag}"
+printfn $"{Convert.ToString(falseFlag).Equals Boolean.FalseString}"
+printfn $"{Convert.ToString trueFlag}"
+printfn $"{Convert.ToString(trueFlag).Equals(Boolean.TrueString)}"
+// The example displays the following output:
+// False
+// True
+// True
+// True
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToString/fs.fsproj b/snippets/fsharp/System/Convert/ToString/fs.fsproj
new file mode 100644
index 00000000000..018b503ebea
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToString/fs.fsproj
@@ -0,0 +1,19 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/snippets/fsharp/System/Convert/ToString/nonnumeric.fs b/snippets/fsharp/System/Convert/ToString/nonnumeric.fs
new file mode 100644
index 00000000000..8abd8ab657f
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToString/nonnumeric.fs
@@ -0,0 +1,85 @@
+module nonnumeric
+
+//
+// Example of Convert.ToString(non-numeric types, IFormatProvider).
+open System
+open System.Globalization
+
+// Create an instance of the IFormatProvider with an object expression.
+let provider =
+ { new IFormatProvider with
+ // Normally, GetFormat returns an object of the requested type
+ // (usually itself) if it is able; otherwise, it returns Nothing.
+ member _.GetFormat(argType: Type) =
+ // Here, the type of argType is displayed, and GetFormat
+ // always returns Nothing.
+ printf $"{argType,-40}"
+ null
+ }
+
+// Convert these values using DummyProvider.
+let Int32A = -252645135
+let DoubleA = 61680.3855
+let ObjDouble = -98765.4321 :> obj
+let DayTimeA = DateTime(2001, 9, 11, 13, 45, 0)
+
+let BoolA = true
+let StringA = "Qwerty"
+let CharA = '$'
+let TSpanA = TimeSpan(0, 18, 0)
+let ObjOther = provider :> obj
+
+[]
+let main _ =
+ printfn
+ """This example of Convert.ToString(non-numeric, IFormatProvider)
+generates the following output. The provider type, argument type,
+and argument value are displayed.
+
+Note: The IFormatProvider object is not called for Boolean, String,
+Char, TimeSpan, and non-numeric Object."""
+
+ // The format provider is called for these conversions.
+ printfn ""
+ let converted = Convert.ToString(Int32A, provider)
+ printfn $"int {converted}"
+ let converted = Convert.ToString(DoubleA, provider)
+ printfn $"double {converted}"
+ let converted = Convert.ToString(ObjDouble, provider)
+ printfn $"object {converted}"
+ let converted = Convert.ToString(DayTimeA, provider)
+ printfn $"DateTime {converted}"
+
+ // The format provider is not called for these conversions.
+ printfn ""
+ let converted = Convert.ToString(BoolA, provider)
+ printfn $"bool {converted}"
+ let converted = Convert.ToString(StringA, provider)
+ printfn $"string {converted}"
+ let converted = Convert.ToString(CharA, provider)
+ printfn $"char {converted}"
+ let converted = Convert.ToString(TSpanA, provider)
+ printfn $"TimeSpan {converted}"
+ let converted = Convert.ToString(ObjOther, provider)
+ printfn $"object {converted}"
+
+ 0
+
+// This example of Convert.ToString(non-numeric, IFormatProvider)
+// generates the following output. The provider type, argument type,
+// and argument value are displayed.
+//
+// Note: The IFormatProvider object is not called for Boolean, String,
+// Char, TimeSpan, and non-numeric Object.
+//
+// System.Globalization.NumberFormatInfo int -252645135
+// System.Globalization.NumberFormatInfo double 61680.3855
+// System.Globalization.NumberFormatInfo object -98765.4321
+// System.Globalization.DateTimeFormatInfo DateTime 9/11/2001 1:45:00 PM
+//
+// bool True
+// string Qwerty
+// char $
+// TimeSpan 00:18:00
+// object DummyProvider
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToString/tostring1.fs b/snippets/fsharp/System/Convert/ToString/tostring1.fs
new file mode 100644
index 00000000000..1e2efc2881d
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToString/tostring1.fs
@@ -0,0 +1,148 @@
+module tostring1
+
+open System
+
+let convertDateTime () =
+ //
+ let dates =
+ [| DateTime(2009, 7, 14)
+ DateTime(1, 1, 1, 18, 32, 0)
+ DateTime(2009, 2, 12, 7, 16, 0) |]
+
+ for dateValue in dates do
+ let result = Convert.ToString dateValue
+ printfn $"Converted the {dateValue.GetType().Name} value {dateValue} to the {result.GetType().Name} value {result}."
+ // The example displays the following output:
+ // Converted the DateTime value 7/14/2009 12:00:00 AM to a String value 7/14/2009 12:00:00 AM.
+ // Converted the DateTime value 1/1/0001 06:32:00 PM to a String value 1/1/0001 06:32:00 PM.
+ // Converted the DateTime value 2/12/2009 07:16:00 AM to a String value 2/12/2009 07:16:00 AM.
+ //
+
+let convertInt16 () =
+ //
+ let numbers = [| Int16.MinValue; -138s; 0s; 19s; Int16.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToString number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ // The example displays the following output:
+ // Converted the Int16 value -32768 to the String value -32768.
+ // Converted the Int16 value -138 to the String value -138.
+ // Converted the Int16 value 0 to the String value 0.
+ // Converted the Int16 value 19 to the String value 19.
+ // Converted the Int16 value 32767 to the String value 32767.
+ //
+
+let convertObject () =
+ //
+ let values: obj[] =
+ [| false; 12.63m; DateTime(2009, 6, 1, 6, 32, 15)
+ 16.09e-12; 'Z'; 15.15322; SByte.MinValue; Int32.MaxValue |]
+
+ for value in values do
+ let result = Convert.ToString value
+ printfn $"Converted the {value.GetType().Name} value {value} to the {result.GetType().Name} value {result}."
+ // The example displays the following output:
+ // Converted the Boolean value False to the String value False.
+ // Converted the Decimal value 12.63 to the String value 12.63.
+ // Converted the DateTime value 6/1/2009 06:32:15 AM to the String value 6/1/2009 06:32:15 AM.
+ // Converted the Double value 1.609E-11 to the String value 1.609E-11.
+ // Converted the Char value Z to the String value Z.
+ // Converted the Double value 15.15322 to the String value 15.15322.
+ // Converted the SByte value -128 to the String value -128.
+ // Converted the Int32 value 2147483647 to the String value 2147483647.
+ //
+
+let convertSByte () =
+ //
+ let numbers = [| SByte.MinValue; -12y; 0y; 16y; SByte.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToString number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ // The example displays the following output:
+ // Converted the SByte value -128 to the String value -128.
+ // Converted the SByte value -12 to the String value -12.
+ // Converted the SByte value 0 to the String value 0.
+ // Converted the SByte value 16 to the String value 16.
+ // Converted the SByte value 127 to the String value 127.
+ //
+
+let convertSingle () =
+ //
+ let numbers =
+ [| Single.MinValue; -1011.351f; -17.45f; -3e-16f; 0f; 4.56e-12f; 16.0001f; 10345.1221f; Single.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToString number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ // The example displays the following output:
+ // Converted the Single value -3.402823E+38 to the String value -3.402823E+38.
+ // Converted the Single value -1011.351 to the String value -1011.351.
+ // Converted the Single value -17.45 to the String value -17.45.
+ // Converted the Single value -3E-16 to the String value -3E-16.
+ // Converted the Single value 0 to the String value 0.
+ // Converted the Single value 4.56E-12 to the String value 4.56E-12.
+ // Converted the Single value 16.0001 to the String value 16.0001.
+ // Converted the Single value 10345.12 to the String value 10345.12.
+ // Converted the Single value 3.402823E+38 to the String value 3.402823E+38.
+ //
+
+let convertUInt16 () =
+ //
+ let numbers = [| UInt16.MinValue; 103us; 1045us; UInt16.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToString number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ // The example displays the following output:
+ // Converted the UInt16 value 0 to the String value 0.
+ // Converted the UInt16 value 103 to the String value 103.
+ // Converted the UInt16 value 1045 to the String value 1045.
+ // Converted the UInt16 value 65535 to the String value 65535.
+ //
+
+let convertUInt32 () =
+ //
+ let numbers = [| UInt32.MinValue; 103u; 1045u; 119543u; UInt32.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToString number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ // The example displays the following output:
+ // Converted the UInt32 value 0 to the String value 0.
+ // Converted the UInt32 value 103 to the String value 103.
+ // Converted the UInt32 value 1045 to the String value 1045.
+ // Converted the UInt32 value 119543 to the String value 119543.
+ // Converted the UInt32 value 4294967295 to the String value 4294967295.
+ //
+
+let convertUInt64 () =
+ //
+ let numbers = [| UInt64.MinValue; 1031uL; 189045uL; UInt64.MaxValue |]
+
+ for number in numbers do
+ let result = Convert.ToString number
+ printfn $"Converted the {number.GetType().Name} value {number} to the {result.GetType().Name} value {result}."
+ // The example displays the following output:
+ // Converted the UInt64 value 0 to the String value 0.
+ // Converted the UInt64 value 1031 to the String value 1031.
+ // Converted the UInt64 value 189045 to the String value 189045.
+ // Converted the UInt64 value 18446744073709551615 to the String value 18446744073709551615.
+ //
+
+convertDateTime ()
+printfn "-----"
+convertInt16 ()
+printfn "-----"
+convertObject ()
+printfn "-----"
+convertSByte ()
+printfn "-----"
+convertSingle ()
+printfn "-----"
+convertUInt16 ()
+printfn "-----"
+convertUInt32 ()
+printfn "-----"
+convertUInt64 ()
diff --git a/snippets/fsharp/System/Convert/ToString/tostring2.fs b/snippets/fsharp/System/Convert/ToString/tostring2.fs
new file mode 100644
index 00000000000..deacd693433
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToString/tostring2.fs
@@ -0,0 +1,175 @@
+module tostring2
+
+open System
+
+
+let convertByte () =
+ //
+ let bases = [| 2; 8; 10; 16 |]
+ let numbers = [| Byte.MinValue; 12uy; 103uy; Byte.MaxValue |]
+
+ for baseValue in bases do
+ printfn $"Base {baseValue} conversion:"
+ for number in numbers do
+ Console.WriteLine(" {0,-5} --> 0x{1}",
+ number, Convert.ToString(number, baseValue))
+ // The example displays the following output:
+ // Base 2 conversion:
+ // 0 --> 0x0
+ // 12 --> 0x1100
+ // 103 --> 0x1100111
+ // 255 --> 0x11111111
+ // Base 8 conversion:
+ // 0 --> 0x0
+ // 12 --> 0x14
+ // 103 --> 0x147
+ // 255 --> 0x377
+ // Base 10 conversion:
+ // 0 --> 0x0
+ // 12 --> 0x12
+ // 103 --> 0x103
+ // 255 --> 0x255
+ // Base 16 conversion:
+ // 0 --> 0x0
+ // 12 --> 0xc
+ // 103 --> 0x67
+ // 255 --> 0xff
+ //
+
+let convertShort () =
+ //
+ let bases = [| 2; 8; 10; 16 |]
+ let numbers = [| Int16.MinValue; -13621s; -18s; 12s; 19142s; Int16.MaxValue |]
+
+ for baseValue in bases do
+ printfn $"Base {baseValue} conversion:"
+ for number in numbers do
+ printfn $" {number,-8} --> 0x{Convert.ToString(number, baseValue)}"
+ // The example displays the following output:
+ // Base 2 conversion:
+ // -32768 --> 0x1000000000000000
+ // -13621 --> 0x1100101011001011
+ // -18 --> 0x1111111111101110
+ // 12 --> 0x1100
+ // 19142 --> 0x100101011000110
+ // 32767 --> 0x111111111111111
+ // Base 8 conversion:
+ // -32768 --> 0x100000
+ // -13621 --> 0x145313
+ // -18 --> 0x177756
+ // 12 --> 0x14
+ // 19142 --> 0x45306
+ // 32767 --> 0x77777
+ // Base 10 conversion:
+ // -32768 --> 0x-32768
+ // -13621 --> 0x-13621
+ // -18 --> 0x-18
+ // 12 --> 0x12
+ // 19142 --> 0x19142
+ // 32767 --> 0x32767
+ // Base 16 conversion:
+ // -32768 --> 0x8000
+ // -13621 --> 0xcacb
+ // -18 --> 0xffee
+ // 12 --> 0xc
+ // 19142 --> 0x4ac6
+ // 32767 --> 0x7fff
+ //
+
+let convertInt () =
+ //
+ let bases = [| 2; 8; 10; 16 |]
+ let numbers =
+ [| Int32.MinValue; -19327543; -13621; -18; 12; 19142; Int32.MaxValue |]
+
+ for baseValue in bases do
+ printfn $"Base {baseValue} conversion:"
+ for number in numbers do
+ printfn $" {number,-15} --> 0x{Convert.ToString(number, baseValue)}"
+ // The example displays the following output:
+ // Base 2 conversion:
+ // -2147483648 --> 0x10000000000000000000000000000000
+ // -19327543 --> 0x11111110110110010001010111001001
+ // -13621 --> 0x11111111111111111100101011001011
+ // -18 --> 0x11111111111111111111111111101110
+ // 12 --> 0x1100
+ // 19142 --> 0x100101011000110
+ // 2147483647 --> 0x1111111111111111111111111111111
+ // Base 8 conversion:
+ // -2147483648 --> 0x20000000000
+ // -19327543 --> 0x37666212711
+ // -13621 --> 0x37777745313
+ // -18 --> 0x37777777756
+ // 12 --> 0x14
+ // 19142 --> 0x45306
+ // 2147483647 --> 0x17777777777
+ // Base 10 conversion:
+ // -2147483648 --> 0x-2147483648
+ // -19327543 --> 0x-19327543
+ // -13621 --> 0x-13621
+ // -18 --> 0x-18
+ // 12 --> 0x12
+ // 19142 --> 0x19142
+ // 2147483647 --> 0x2147483647
+ // Base 16 conversion:
+ // -2147483648 --> 0x80000000
+ // -19327543 --> 0xfed915c9
+ // -13621 --> 0xffffcacb
+ // -18 --> 0xffffffee
+ // 12 --> 0xc
+ // 19142 --> 0x4ac6
+ // 2147483647 --> 0x7fffffff
+ //
+
+let convertLong () =
+ //
+ let bases = [| 2; 8; 10; 16 |]
+ let numbers =
+ [| Int64.MinValue; -193275430; -13621; -18; 12; 1914206117; Int64.MaxValue |]
+
+ for baseValue in bases do
+ printfn $"Base {baseValue} conversion:"
+ for number in numbers do
+ printfn $" {number,-23} --> 0x{Convert.ToString(number, baseValue)}"
+ // The example displays the following output:
+ // Base 2 conversion:
+ // -9223372036854775808 --> 0x1000000000000000000000000000000000000000000000000000000000000000
+ // -193275430 --> 0x1111111111111111111111111111111111110100011110101101100111011010
+ // -13621 --> 0x1111111111111111111111111111111111111111111111111100101011001011
+ // -18 --> 0x1111111111111111111111111111111111111111111111111111111111101110
+ // 12 --> 0x1100
+ // 1914206117 --> 0x1110010000110000111011110100101
+ // 9223372036854775807 --> 0x111111111111111111111111111111111111111111111111111111111111111
+ // Base 8 conversion:
+ // -9223372036854775808 --> 0x1000000000000000000000
+ // -193275430 --> 0x1777777777776436554732
+ // -13621 --> 0x1777777777777777745313
+ // -18 --> 0x1777777777777777777756
+ // 12 --> 0x14
+ // 1914206117 --> 0x16206073645
+ // 9223372036854775807 --> 0x777777777777777777777
+ // Base 10 conversion:
+ // -9223372036854775808 --> 0x-9223372036854775808
+ // -193275430 --> 0x-193275430
+ // -13621 --> 0x-13621
+ // -18 --> 0x-18
+ // 12 --> 0x12
+ // 1914206117 --> 0x1914206117
+ // 9223372036854775807 --> 0x9223372036854775807
+ // Base 16 conversion:
+ // -9223372036854775808 --> 0x8000000000000000
+ // -193275430 --> 0xfffffffff47ad9da
+ // -13621 --> 0xffffffffffffcacb
+ // -18 --> 0xffffffffffffffee
+ // 12 --> 0xc
+ // 1914206117 --> 0x721877a5
+ // 9223372036854775807 --> 0x7fffffffffffffff
+ //
+
+convertByte ()
+printfn "-----"
+convertShort ()
+printfn "-----"
+convertInt ()
+printfn "-----"
+convertLong ()
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToString/tostring3.fs b/snippets/fsharp/System/Convert/ToString/tostring3.fs
new file mode 100644
index 00000000000..2e927100d60
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToString/tostring3.fs
@@ -0,0 +1,292 @@
+module tostring3
+
+open System
+open System.Globalization
+
+let convertDateTimeWithProvider () =
+ //
+ // Specify the date to be formatted using various cultures.
+ let tDate = DateTime(2010, 4, 15, 20, 30, 40, 333)
+ // Specify the cultures.
+ let cultureNames =
+ [| "en-US"; "es-AR"; "fr-FR"; "hi-IN";
+ "ja-JP"; "nl-NL"; "ru-RU"; "ur-PK" |]
+
+ printfn $"Converting the date {Convert.ToString(tDate, CultureInfo.InvariantCulture)}: "
+
+ for cultureName in cultureNames do
+ let culture = CultureInfo cultureName
+ let dateString = Convert.ToString(tDate, culture)
+ printfn $" {culture.Name}: {dateString,-12}"
+ // The example displays the following output:
+ // Converting the date 04/15/2010 20:30:40:
+ // en-US: 4/15/2010 8:30:40 PM
+ // es-AR: 15/04/2010 08:30:40 p.m.
+ // fr-FR: 15/04/2010 20:30:40
+ // hi-IN: 15-04-2010 20:30:40
+ // ja-JP: 2010/04/15 20:30:40
+ // nl-NL: 15-4-2010 20:30:40
+ // ru-RU: 15.04.2010 20:30:40
+ // ur-PK: 15/04/2010 8:30:40 PM
+ //
+
+let convertDecimalWithProvider () =
+ //
+ // Define an array of numbers to display.
+ let numbers =
+ [| 1734231911290.16m; -17394.32921m; 3193.23m; 98012368321.684m |]
+ // Define the culture names used to display them.
+ let cultureNames = [| "en-US"; "fr-FR"; "ja-JP"; "ru-RU" |]
+
+ for number in numbers do
+ printfn $"{Convert.ToString(number, CultureInfo.InvariantCulture)}:"
+ for cultureName in cultureNames do
+ let culture = CultureInfo cultureName
+ printfn $" {culture.Name}: {Convert.ToString(number, culture),20}"
+ printfn ""
+ // The example displays the following output:
+ // 1734231911290.16:
+ // en-US: 1734231911290.16
+ // fr-FR: 1734231911290,16
+ // ja-JP: 1734231911290.16
+ // ru-RU: 1734231911290,16
+ //
+ // -17394.32921:
+ // en-US: -17394.32921
+ // fr-FR: -17394,32921
+ // ja-JP: -17394.32921
+ // ru-RU: -17394,32921
+ //
+ // 3193.23:
+ // en-US: 3193.23
+ // fr-FR: 3193,23
+ // ja-JP: 3193.23
+ // ru-RU: 3193,23
+ //
+ // 98012368321.684:
+ // en-US: 98012368321.684
+ // fr-FR: 98012368321,684
+ // ja-JP: 98012368321.684
+ // ru-RU: 98012368321,684
+ //
+
+let convertDoubleWithProvider () =
+ //
+ // Define an array of numbers to display.
+ let numbers = [| -1.5345e16; -123.4321; 19092.123; 1.1734231911290e16 |]
+ // Define the culture names used to display them.
+ let cultureNames = [| "en-US"; "fr-FR"; "ja-JP"; "ru-RU" |]
+
+ for number in numbers do
+ printfn $"{Convert.ToString(number, CultureInfo.InvariantCulture)}:"
+ for cultureName in cultureNames do
+ let culture = CultureInfo cultureName
+ printfn " {culture.Name}: {Convert.ToString(number, culture),20}"
+ printfn ""
+ // The example displays the following output:
+ // -1.5345E+16:
+ // en-US: -1.5345E+16
+ // fr-FR: -1,5345E+16
+ // ja-JP: -1.5345E+16
+ // ru-RU: -1,5345E+16
+ //
+ // -123.4321:
+ // en-US: -123.4321
+ // fr-FR: -123,4321
+ // ja-JP: -123.4321
+ // ru-RU: -123,4321
+ //
+ // 19092.123:
+ // en-US: 19092.123
+ // fr-FR: 19092,123
+ // ja-JP: 19092.123
+ // ru-RU: 19092,123
+ //
+ // 1.173423191129E+16:
+ // en-US: 1.173423191129E+16
+ // fr-FR: 1,173423191129E+16
+ // ja-JP: 1.173423191129E+16
+ // ru-RU: 1,173423191129E+16
+ //
+
+let convertByteWithProvider () =
+ //
+ let numbers = [| 12uy; 100uy; Byte.MaxValue |]
+ // Define the culture names used to display them.
+ let cultureNames = [| "en-US"; "fr-FR" |]
+
+ for number in numbers do
+ printfn $"{Convert.ToString(number, CultureInfo.InvariantCulture)}:"
+ for cultureName in cultureNames do
+ let culture = CultureInfo cultureName
+ printfn $" {culture.Name}: {Convert.ToString(number, culture),20}"
+ printfn ""
+ // The example displays the following output:
+ // 12:
+ // en-US: 12
+ // fr-FR: 12
+ //
+ // 100:
+ // en-US: 100
+ // fr-FR: 100
+ //
+ // 255:
+ // en-US: 255
+ // fr-FR: 255
+ //
+
+let convertSByteWithProvider () =
+ //
+ let numbers = [| SByte.MinValue; -12y; 17y; SByte.MaxValue |]
+ let nfi = NumberFormatInfo()
+ nfi.NegativeSign <- "~"
+ nfi.PositiveSign <- "!"
+ for number in numbers do
+ printfn $"{Convert.ToString(number, nfi)}"
+ // The example displays the following output:
+ // ~128
+ // ~12
+ // 17
+ // 127
+ //
+
+let convertSingleWithProvider () =
+ //
+ // Define an array of numbers to display.
+ let numbers = [| -1.5345e16f; -123.4321f; 19092.123f; 1.1734231911290e16f |]
+ // Define the culture names used to display them.
+ let cultureNames = [| "en-US"; "fr-FR"; "ja-JP"; "ru-RU" |]
+
+ for number in numbers do
+ printfn $"{Convert.ToString(number, CultureInfo.InvariantCulture)}:"
+ for cultureName in cultureNames do
+ let culture = CultureInfo cultureName
+ printfn $" {culture.Name}: {Convert.ToString(number, culture),20}"
+ printfn ""
+ // The example displays the following output:
+ // -1.5345E+16:
+ // en-US: -1.5345E+16
+ // fr-FR: -1,5345E+16
+ // ja-JP: -1.5345E+16
+ // ru-RU: -1,5345E+16
+ //
+ // -123.4321:
+ // en-US: -123.4321
+ // fr-FR: -123,4321
+ // ja-JP: -123.4321
+ // ru-RU: -123,4321
+ //
+ // 19092.123:
+ // en-US: 19092.123
+ // fr-FR: 19092,123
+ // ja-JP: 19092.123
+ // ru-RU: 19092,123
+ //
+ // 1.173423191129E+16:
+ // en-US: 1.173423191129E+16
+ // fr-FR: 1,173423191129E+16
+ // ja-JP: 1.173423191129E+16
+ // ru-RU: 1,173423191129E+16
+ //
+
+let convertInt16WithProvider () =
+ //
+ let numbers = [| Int16.MinValue; Int16.MaxValue |]
+ let nfi = NumberFormatInfo()
+ nfi.NegativeSign <- "~"
+ nfi.PositiveSign <- "!"
+
+ for number in numbers do
+ printfn $"{Convert.ToString(number, CultureInfo.InvariantCulture),-8} --> {Convert.ToString(number, nfi),8}"
+ // The example displays the following output:
+ // -32768 --> ~32768
+ // 32767 --> 32767
+ //
+
+let convertInt32WithProvider () =
+ //
+ let numbers = [| Int32.MinValue; Int32.MaxValue |]
+ let nfi = NumberFormatInfo()
+ nfi.NegativeSign <- "~"
+ nfi.PositiveSign <- "!"
+
+ for number in numbers do
+ printfn $"{Convert.ToString(number, CultureInfo.InvariantCulture),-12} --> {Convert.ToString(number, nfi),12}"
+ // The example displays the following output:
+ // -2147483648 --> ~2147483648
+ // 2147483647 --> 2147483647
+ //
+
+let convertInt64WithProvider () =
+ //
+ let numbers = [| (int64 Int32.MinValue) * 2L; (int64 Int32.MaxValue) * 2L |]
+ let nfi = NumberFormatInfo()
+ nfi.NegativeSign <- "~"
+ nfi.PositiveSign <- "!"
+
+ for number in numbers do
+ printfn $"{Convert.ToString(number, CultureInfo.InvariantCulture),-12} --> {Convert.ToString(number, nfi),12}"
+ // The example displays the following output:
+ // -4294967296 --> ~4294967296
+ // 4294967294 --> 4294967294
+ //
+
+let convertUInt16WithProvider () =
+ //
+ let number = UInt16.MaxValue
+ let nfi = NumberFormatInfo()
+ nfi.NegativeSign <- "~"
+ nfi.PositiveSign <- "!"
+
+ printfn $"{Convert.ToString(number, CultureInfo.InvariantCulture),-6} --> {Convert.ToString(number, nfi),6}"
+ // The example displays the following output:
+ // 65535 --> 65535
+ //
+
+let convertUInt32WithProvider () =
+ //
+ let number = UInt32.MaxValue
+ let nfi = NumberFormatInfo()
+ nfi.NegativeSign <- "~"
+ nfi.PositiveSign <- "!"
+
+ printfn $"{Convert.ToString(number, CultureInfo.InvariantCulture),-8} --> {Convert.ToString(number, nfi),8}"
+ // The example displays the following output:
+ // 4294967295 --> 4294967295
+ //
+
+let convertUInt64WithProvider () =
+ //
+ let number = UInt64.MaxValue
+ let nfi = NumberFormatInfo()
+ nfi.NegativeSign <- "~"
+ nfi.PositiveSign <- "!"
+
+ printfn $"{Convert.ToString(number, CultureInfo.InvariantCulture),-12} --> {Convert.ToString(number, nfi),12}"
+ // The example displays the following output:
+ // 18446744073709551615 --> 18446744073709551615
+ //
+
+convertDateTimeWithProvider ()
+printfn "-----"
+convertDecimalWithProvider ()
+printfn "-----"
+convertDoubleWithProvider ()
+printfn "-----"
+convertByteWithProvider ()
+printfn "-----"
+convertSByteWithProvider ()
+printfn "-----"
+convertSingleWithProvider ()
+printfn "-----"
+convertInt16WithProvider ()
+printfn "-----"
+convertInt32WithProvider ()
+printfn "-----"
+convertInt64WithProvider ()
+printfn "-----"
+convertUInt16WithProvider ()
+printfn "-----"
+convertUInt32WithProvider ()
+printfn "-----"
+convertUInt64WithProvider ()
diff --git a/snippets/fsharp/System/Convert/ToString/tostring5.fs b/snippets/fsharp/System/Convert/ToString/tostring5.fs
new file mode 100644
index 00000000000..a196b2ac0ab
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToString/tostring5.fs
@@ -0,0 +1,30 @@
+module tostring5
+
+//
+open System
+
+type Temperature(temperature: decimal) =
+ member _.Celsius =
+ temperature
+
+ member _.Kelvin =
+ temperature + 273.15m
+
+ member _.Fahrenheit =
+ Math.Round(temperature * 9m / 5m + 32m |> decimal, 2)
+
+ override _.ToString() =
+ temperature.ToString("N2") + " °C"
+
+let cold = Temperature -40
+let freezing = Temperature 0
+let boiling = Temperature 100
+
+printfn $"{Convert.ToString(cold, null)}"
+printfn $"{Convert.ToString(freezing, null)}"
+printfn $"{Convert.ToString(boiling, null)}"
+// The example dosplays the following output:
+// -40.00 °C
+// 0.00 °C
+// 100.00 °C
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToString/tostring6.fs b/snippets/fsharp/System/Convert/ToString/tostring6.fs
new file mode 100644
index 00000000000..955592b0691
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToString/tostring6.fs
@@ -0,0 +1,22 @@
+module tostring6
+
+open System
+
+let convertInt64 () =
+ //
+ // Create a NumberFormatInfo object and set several of its
+ // properties that control default integer formatting.
+ let provider = System.Globalization.NumberFormatInfo()
+ provider.NegativeSign <- "minus "
+
+ let values = [| -200; 0; 1000 |]
+
+ for value in values do
+ printfn $"{value,-6} --> {Convert.ToString(value, provider),10}"
+ // The example displays the following output:
+ // -200 --> minus 200
+ // 0 --> 0
+ // 1000 --> 1000
+ //
+
+convertInt64 ()
diff --git a/snippets/fsharp/System/Convert/ToString/tostring7.fs b/snippets/fsharp/System/Convert/ToString/tostring7.fs
new file mode 100644
index 00000000000..d2593b28f0d
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToString/tostring7.fs
@@ -0,0 +1,24 @@
+module tostring7
+
+//
+open System
+open System.Globalization
+
+// Create a NumberFormatInfo object and set its NegativeSigns
+// property to use for integer formatting.
+let provider = NumberFormatInfo()
+provider.NegativeSign <- "minus "
+
+let values = [| -20; 0; 100 |]
+
+printfn $"""{CultureInfo.CurrentCulture.Name,-8} --> {"Value",10} {"Custom",10}\n"""
+
+for value in values do
+ printfn $"{value,-8} --> {Convert.ToString value,10} {Convert.ToString(value, provider),10}"
+// The example displays output like the following:
+// Value --> en-US Custom
+//
+// -20 --> -20 minus 20
+// 0 --> 0 0
+// 100 --> 100 100
+//
diff --git a/snippets/fsharp/System/Convert/ToString/tostring_obj30.fs b/snippets/fsharp/System/Convert/ToString/tostring_obj30.fs
new file mode 100644
index 00000000000..4dde7087fb1
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToString/tostring_obj30.fs
@@ -0,0 +1,71 @@
+module tostring_obj30
+
+//
+open System
+
+[]
+type TemperatureProvider() =
+ let fmtStrings = [| "C"; "G"; "F"; "K" |]
+ let rnd = Random()
+
+ member _.Format =
+ fmtStrings[rnd.Next(0, fmtStrings.Length)]
+
+ interface IFormatProvider with
+ member this.GetFormat(formatType: Type) =
+ this
+
+type Temperature(temperature: decimal) =
+ member _.Celsius =
+ temperature
+ member _.Kelvin =
+ temperature + 273.15m
+
+ member _.Fahrenheit =
+ Math.Round(temperature * 9m / 5m + 32m, 2)
+
+ override this.ToString() =
+ this.ToString("G", null)
+
+ member this.ToString(fmt: string, provider: IFormatProvider) =
+ let formatter =
+ match provider with
+ | null -> null
+ | _ ->
+ match provider.GetFormat typeof with
+ | :? TemperatureProvider as x -> x
+ | _ -> null
+
+ let fmt =
+ if String.IsNullOrWhiteSpace fmt then
+ if formatter <> null then
+ formatter.Format
+ else
+ "G"
+ else fmt
+
+ match fmt.ToUpper() with
+ | "G"
+ | "C" ->
+ $"{temperature:N2} °C"
+ | "F" ->
+ $"{this.Fahrenheit:N2} °F"
+ | "K" ->
+ $"{this.Kelvin:N2} K"
+ | _ ->
+ raise (FormatException $"'{fmt}' is not a valid format specifier.")
+
+let cold = Temperature -40
+let freezing = Temperature 0
+let boiling = Temperature 100
+
+let tp = TemperatureProvider()
+
+printfn $"{Convert.ToString(cold, tp)}"
+printfn $"{Convert.ToString(freezing, tp)}"
+printfn $"{Convert.ToString(boiling, tp)}"
+// The example displays output like the following:
+// -40.00 °C
+// 273.15 K
+// 100.00 °C
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToString/tostring_string1.fs b/snippets/fsharp/System/Convert/ToString/tostring_string1.fs
new file mode 100644
index 00000000000..9e6b0040504
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToString/tostring_string1.fs
@@ -0,0 +1,17 @@
+module tostring_string1
+
+//
+open System
+
+let article = "An"
+let noun = "apple"
+let str1 = $"{article} {noun}"
+let str2 = Convert.ToString str1
+
+printfn $"str1 is interned: {String.IsInterned str1 <> null}"
+
+printfn $"str1 and str2 are the same reference: {Object.ReferenceEquals(str1, str2)}"
+// The example displays the following output:
+// str1 is interned: False
+// str1 and str2 are the same reference: True
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToUInt16/fs.fsproj b/snippets/fsharp/System/Convert/ToUInt16/fs.fsproj
new file mode 100644
index 00000000000..e1363cb598e
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToUInt16/fs.fsproj
@@ -0,0 +1,12 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToUInt16/touint16_1.fs b/snippets/fsharp/System/Convert/ToUInt16/touint16_1.fs
new file mode 100644
index 00000000000..43218d756b4
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToUInt16/touint16_1.fs
@@ -0,0 +1,314 @@
+module touint16_1
+
+open System
+
+let convertBoolean () =
+ //
+ let falseFlag = false
+ let trueFlag = true
+
+ printfn $"{falseFlag} converts to {Convert.ToInt16 falseFlag}."
+ printfn $"{trueFlag} converts to {Convert.ToInt16 trueFlag}."
+ // The example displays the following output:
+ // False converts to 0.
+ // True converts to 1.
+ //
+
+let convertByte () =
+ //
+ let bytes = [| Byte.MinValue; 14uy; 122uy; Byte.MaxValue |]
+
+ for byteValue in bytes do
+ let result = Convert.ToUInt16 byteValue
+ printfn $"Converted the {byteValue.GetType().Name} value '{byteValue}' to the {result.GetType().Name} value {result}."
+ // The example displays the following output:
+ // Converted the Byte value '0' to the UInt16 value 0.
+ // Converted the Byte value '14' to the UInt16 value 14.
+ // Converted the Byte value '122' to the UInt16 value 122.
+ // Converted the Byte value '255' to the UInt16 value 255.
+ //
+
+let convertChar () =
+ //
+ let chars =
+ [| 'a'; 'z'; '\u0007'; '\u03FF'; '\u7FFF'; '\uFFFE' |]
+
+ for ch in chars do
+ try
+ let result = Convert.ToUInt16 ch
+ printfn $"Converted the {ch.GetType().Name} value '{ch}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"Unable to convert u+{int ch:X4} to a UInt16."
+ // The example displays the following output:
+ // Converted the Char value 'a' to the UInt16 value 97.
+ // Converted the Char value 'z' to the UInt16 value 122.
+ // Converted the Char value '' to the UInt16 value 7.
+ // Converted the Char value '?' to the UInt16 value 1023.
+ // Converted the Char value '?' to the UInt16 value 32767.
+ // Converted the Char value '?' to the UInt16 value 65534.
+ //
+
+let convertDecimal () =
+ //
+ let numbers =
+ [| Decimal.MinValue; -1034.23m; -12m; 0m; 147m; 9214.16m; Decimal.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToUInt16 number
+ printfn $"Converted the {number.GetType().Name} value '{number}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"{number} is outside the range of the UInt16 type."
+ // The example displays the following output:
+ // -79228162514264337593543950335 is outside the range of the UInt16 type.
+ // -1034.23 is outside the range of the UInt16 type.
+ // -12 is outside the range of the UInt16 type.
+ // Converted the Decimal value '0' to the UInt16 value 0.
+ // Converted the Decimal value '147' to the UInt16 value 147.
+ // Converted the Decimal value '9214.16' to the UInt16 value 9214.
+ // 79228162514264337593543950335 is outside the range of the UInt16 type.
+ //
+
+let convertDouble () =
+ //
+ let numbers =
+ [| Double.MinValue; -1.38e10; -1023.299; -12.98
+ 0; 9.113e-16; 103.919; 17834.191; Double.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToUInt16 number
+ printfn $"Converted the {number.GetType().Name} value '{number}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"{number} is outside the range of the UInt16 type."
+ // The example displays the following output:
+ // -1.79769313486232E+308 is outside the range of the UInt16 type.
+ // -13800000000 is outside the range of the UInt16 type.
+ // -1023.299 is outside the range of the UInt16 type.
+ // -12.98 is outside the range of the UInt16 type.
+ // Converted the Double value '0' to the UInt16 value 0.
+ // Converted the Double value '9.113E-16' to the UInt16 value 0.
+ // Converted the Double value '103.919' to the UInt16 value 104.
+ // Converted the Double value '17834.191' to the UInt16 value 17834.
+ // 1.79769313486232E+308 is outside the range of the UInt16 type.
+ //
+
+let convertInt16 () =
+ //
+ let numbers = [| Int16.MinValue; -132s; 0s; 121s; 16103s; Int16.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToUInt16 number
+ printfn $"Converted the {number.GetType().Name} value '{number}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"The {number.GetType().Name} value {number} is outside the range of the UInt16 type."
+ // The example displays the following output:
+ // The Int16 value -32768 is outside the range of the UInt16 type.
+ // The Int16 value -132 is outside the range of the UInt16 type.
+ // Converted the Int16 value '0' to the UInt16 value 0.
+ // Converted the Int16 value '121' to the UInt16 value 121.
+ // Converted the Int16 value '16103' to the UInt16 value 16103.
+ // Converted the Int16 value '32767' to the UInt16 value 32767.
+ //
+
+let convertInt32 () =
+ //
+ let numbers = [| Int32.MinValue; -1; 0; 121; 340; Int32.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToUInt16 number
+ printfn $"Converted the {number.GetType().Name} value '{number}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn "The {number.GetType().Name} value {number} is outside the range of the UInt16 type."
+
+ // The example displays the following output:
+ // The Int32 value -2147483648 is outside the range of the UInt16 type.
+ // The Int32 value -1 is outside the range of the UInt16 type.
+ // Converted the Int32 value '0' to the UInt16 value 0.
+ // Converted the Int32 value '121' to the UInt16 value 121.
+ // Converted the Int32 value '340' to the UInt16 value 340.
+ // The Int32 value 2147483647 is outside the range of the UInt16 type.
+ //
+
+let convertInt64 () =
+ //
+ let numbers = [| Int64.MinValue; -1; 0; 121; 340; Int64.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToUInt16 number
+ printfn $"Converted the {number.GetType().Name} value '{number}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn "The {number.GetType().Name} value {number} is outside the range of the UInt16 type."
+ // The example displays the following output:
+ // The Int64 value -9223372036854775808 is outside the range of the UInt16 type.
+ // The Int64 value -1 is outside the range of the UInt16 type.
+ // Converted the Int64 value '0' to the UInt16 value 0.
+ // Converted the Int64 value '121' to the UInt16 value 121.
+ // Converted the Int64 value '340' to the UInt16 value 340.
+ // The Int64 value 9223372036854775807 is outside the range of the UInt16 type.
+ //
+
+let convertObject () =
+ //
+ let values: obj[] =
+ [| true; -12; 163; 935; 'x'; DateTime(2009, 5, 12)
+ "104"; "103.0"; "-1"; "1.00e2"; "One"; 1.00e2 |]
+
+ for value in values do
+ try
+ let result = Convert.ToUInt16 value
+ printfn $"Converted the {value.GetType().Name} value '{value}' to the {result.GetType().Name} value {result}."
+ with
+ | :? OverflowException ->
+ printfn $"The {value.GetType().Name} value {value} is outside the range of the UInt16 type."
+ | :? FormatException ->
+ printfn $"The {value.GetType().Name} value {value} is not in a recognizable format."
+ | :? InvalidCastException ->
+ printfn $"No conversion to a UInt16 exists for the {value.GetType().Name} value {value}."
+ // The example displays the following output:
+ // Converted the Boolean value 'True' to the UInt16 value 1.
+ // The Int32 value -12 is outside the range of the UInt16 type.
+ // Converted the Int32 value '163' to the UInt16 value 163.
+ // Converted the Int32 value '935' to the UInt16 value 935.
+ // Converted the Char value 'x' to the UInt16 value 120.
+ // No conversion to a UInt16 exists for the DateTime value 5/12/2009 12:00:00 AM.
+ // Converted the String value '104' to the UInt16 value 104.
+ // The String value 103.0 is not in a recognizable format.
+ // The String value -1 is outside the range of the UInt16 type.
+ // The String value 1.00e2 is not in a recognizable format.
+ // The String value One is not in a recognizable format.
+ // Converted the Double value '100' to the UInt16 value 100.
+ //
+
+let convertSByte () =
+ //
+ let numbers = [| SByte.MinValue; -1y; 0y; 10y; SByte.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToUInt16 number
+ printfn $"Converted the {number.GetType().Name} value '{number}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"{number} is outside the range of the UInt16 type."
+ // The example displays the following output:
+ // -128 is outside the range of the UInt16 type.
+ // -1 is outside the range of the UInt16 type.
+ // Converted the SByte value '0' to the UInt16 value 0.
+ // Converted the SByte value '10' to the UInt16 value 10.
+ // Converted the SByte value '127' to the UInt16 value 127.
+ //
+
+let convertSingle () =
+ //
+ let numbers =
+ [| Single.MinValue; -1.38e10f; -1023.299f; -12.98f
+ 0f; 9.113e-16f; 103.919f; 17834.191f; Single.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToUInt16 number
+ printfn $"Converted the {number.GetType().Name} value '{number}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"{number} is outside the range of the UInt16 type."
+ // The example displays the following output:
+ // -3.402823E+38 is outside the range of the UInt16 type.
+ // -1.38E+10 is outside the range of the UInt16 type.
+ // -1023.299 is outside the range of the UInt16 type.
+ // -12.98 is outside the range of the UInt16 type.
+ // Converted the Single value '0' to the UInt16 value 0.
+ // Converted the Single value '9.113E-16' to the UInt16 value 0.
+ // Converted the Single value '103.919' to the UInt16 value 104.
+ // Converted the Single value '17834.19' to the UInt16 value 17834.
+ // 3.402823E+38 is outside the range of the UInt16 type.
+ //
+
+let convertString () =
+ //
+ let values =
+ [| "1603"; "1,603"; "one"; "1.6e03"
+ "1.2e-02"; "-1326"; "1074122" |]
+
+ for value in values do
+ try
+ let result = Convert.ToUInt16 value
+ printfn $"Converted the {value.GetType().Name} value '{value}' to the {result.GetType().Name} value {result}."
+ with
+ | :? FormatException ->
+ printfn $"The {value.GetType().Name} value {value} is not in a recognizable format."
+ | :? OverflowException ->
+ printfn $"{value} is outside the range of the UInt16 type."
+ // The example displays the following output:
+ // Converted the String value '1603' to the UInt16 value 1603.
+ // The String value 1,603 is not in a recognizable format.
+ // The String value one is not in a recognizable format.
+ // The String value 1.6e03 is not in a recognizable format.
+ // The String value 1.2e-02 is not in a recognizable format.
+ // -1326 is outside the range of the UInt16 type.
+ // 1074122 is outside the range of the UInt16 type.
+ //
+
+let convertUInt32 () =
+ //
+ let numbers = [| UInt32.MinValue; 121u; 340u; UInt32.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToUInt16 number
+ printfn $"Converted the {number.GetType().Name} value '{number}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"The {number.GetType().Name} value {number} is outside the range of the UInt16 type."
+
+ // The example displays the following output:
+ // Converted the UInt32 value '0' to the UInt16 value 0.
+ // Converted the UInt32 value '121' to the UInt16 value 121.
+ // Converted the UInt32 value '340' to the UInt16 value 340.
+ // The UInt32 value 4294967295 is outside the range of the UInt16 type.
+ //
+
+let convertUInt64 () =
+ //
+ let numbers = [| UInt64.MinValue; 121uL; 340uL; UInt64.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToUInt16 number
+ printfn $"Converted the {number.GetType().Name} value '{number}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"The {number.GetType().Name} value {number} is outside the range of the UInt16 type."
+ // The example displays the following output:
+ // Converted the UInt64 value '0' to the UInt16 value 0.
+ // Converted the UInt64 value '121' to the UInt16 value 121.
+ // Converted the UInt64 value '340' to the UInt16 value 340.
+ // The UInt64 value 18446744073709551615 is outside the range of the UInt16 type.
+ //
+
+convertBoolean ()
+printfn "-----"
+convertByte ()
+printfn "-----"
+convertChar ()
+printfn "-----"
+convertDecimal ()
+printfn "-----"
+convertDouble ()
+printfn "----"
+convertInt16 ()
+printfn "-----"
+convertInt32 ()
+printfn "-----"
+convertInt64 ()
+printfn "-----"
+convertObject ()
+printfn "-----"
+convertSByte ()
+printfn "-----"
+convertSingle ()
+printfn "----"
+convertString()
+printfn "-----"
+convertUInt32 ()
+printfn "-----"
+convertUInt64 ()
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToUInt16/touint16_2.fs b/snippets/fsharp/System/Convert/ToUInt16/touint16_2.fs
new file mode 100644
index 00000000000..432ca4ceb99
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToUInt16/touint16_2.fs
@@ -0,0 +1,29 @@
+module touint16_2
+
+//
+open System
+
+let hexStrings =
+ [| "8000"; "0FFF"; "f000"; "00A30"
+ "D"; "-13"; "9AC61"; "GAD" |]
+for hexString in hexStrings do
+ try
+ let number = Convert.ToUInt16(hexString, 16)
+ printfn $"Converted '{hexString}' to {number:N0}."
+ with
+ | :? FormatException ->
+ printfn $"'{hexString}' is not in the correct format for a hexadecimal number."
+ | :? OverflowException ->
+ printfn $"'{hexString}' is outside the range of an Int16."
+ | :? ArgumentException ->
+ printfn $"'{hexString}' is invalid in base 16."
+// The example displays the following output:
+// Converted '8000' to 32,768.
+// Converted '0FFF' to 4,095.
+// Converted 'f000' to 61,440.
+// Converted '00A30' to 2,608.
+// Converted 'D' to 13.
+// '-13' is invalid in base 16.
+// '9AC61' is outside the range of an Int16.
+// 'GAD' is not in the correct format for a hexadecimal number.
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToUInt16/touint16_3.fs b/snippets/fsharp/System/Convert/ToUInt16/touint16_3.fs
new file mode 100644
index 00000000000..40dd846ec40
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToUInt16/touint16_3.fs
@@ -0,0 +1,196 @@
+module touint16_3
+
+//
+open System
+open System.Globalization
+open System.Text.RegularExpressions
+
+type SignBit =
+ | Negative = -1
+ | Zero = 0
+ | Positive = 1
+
+[]
+type HexString =
+ val mutable private hexString: string
+
+ val mutable Sign: SignBit
+
+ member this.Value
+ with get () = this.hexString
+ and set (value: string) =
+ if value.Trim().Length > 4 then
+ invalidArg "value" "The string representation of a 16 bit integer cannot have more than four characters."
+ elif Regex.IsMatch(value, "([0-9,A-F]){1,4}", RegexOptions.IgnoreCase) |> not then
+ invalidArg "value" "The hexadecimal representation of a 16-bit integer contains invalid characters."
+ else
+ this.hexString <- value
+
+ interface IConvertible with
+ // IConvertible implementations.
+ member _.GetTypeCode() =
+ TypeCode.Object
+
+ member this.ToBoolean(provider: IFormatProvider) =
+ this.Sign <> SignBit.Zero
+
+ member this.ToByte(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ raise (OverflowException $"{Convert.ToInt16(this.hexString, 16)} is out of range of the Byte type.")
+ else
+ try
+ Convert.ToByte(UInt16.Parse(this.hexString, NumberStyles.HexNumber))
+ with :? OverflowException as e ->
+ raise (OverflowException($"{Convert.ToUInt16(this.hexString, 16)} is out of range of the UInt16 type.", e) )
+
+ member this.ToChar(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ raise (OverflowException $"{Convert.ToInt16(this.hexString, 16)} is out of range of the Char type.")
+
+ let codePoint = UInt16.Parse(this.hexString, NumberStyles.HexNumber)
+ Convert.ToChar codePoint
+
+ member _.ToDateTime(provider: IFormatProvider) =
+ raise (InvalidCastException "Hexadecimal to DateTime conversion is not supported.")
+
+ member this.ToDecimal(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ let hexValue = Int16.Parse(this.hexString, NumberStyles.HexNumber)
+ Convert.ToDecimal hexValue
+ else
+ let hexValue = UInt16.Parse(this.hexString, NumberStyles.HexNumber)
+ Convert.ToDecimal hexValue
+
+ member this.ToDouble(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ Convert.ToDouble(Int16.Parse(this.hexString, NumberStyles.HexNumber))
+ else
+ Convert.ToDouble(UInt16.Parse(this.hexString, NumberStyles.HexNumber))
+
+ member this.ToInt16(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ Int16.Parse(this.hexString, NumberStyles.HexNumber)
+ else
+ try
+ Convert.ToInt16(UInt16.Parse(this.hexString, NumberStyles.HexNumber))
+ with :? OverflowException as e ->
+ raise (OverflowException($"{Convert.ToUInt16(this.hexString, 16)} is out of range of the Int16 type.", e) )
+
+ member this.ToInt32(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ Convert.ToInt32(Int16.Parse(this.hexString, NumberStyles.HexNumber))
+ else
+ Convert.ToInt32(UInt16.Parse(this.hexString, NumberStyles.HexNumber))
+
+ member this.ToInt64(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ Convert.ToInt64(Int16.Parse(this.hexString, NumberStyles.HexNumber))
+ else
+ Int64.Parse(this.hexString, NumberStyles.HexNumber)
+
+ member this.ToSByte(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ try
+ Convert.ToSByte(Int16.Parse(this.hexString, NumberStyles.HexNumber))
+ with :? OverflowException as e ->
+ raise (OverflowException($"{Int16.Parse(this.hexString, NumberStyles.HexNumber)} is outside the range of the SByte type.", e))
+ else
+ try
+ Convert.ToSByte(UInt16.Parse(this.hexString, NumberStyles.HexNumber))
+ with :? OverflowException as e ->
+ raise (OverflowException($"{UInt16.Parse(this.hexString, NumberStyles.HexNumber)} is outside the range of the SByte type.", e) )
+
+ member this.ToSingle(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ Convert.ToSingle(Int16.Parse(this.hexString, NumberStyles.HexNumber))
+ else
+ Convert.ToSingle(UInt16.Parse(this.hexString, NumberStyles.HexNumber))
+
+ member this.ToString(provider: IFormatProvider) =
+ "0x" + this.hexString
+
+ member this.ToType(conversionType: Type, provider: IFormatProvider) =
+ let this = this :> IConvertible
+ match Type.GetTypeCode conversionType with
+ | TypeCode.Boolean ->
+ this.ToBoolean null
+ | TypeCode.Byte ->
+ this.ToByte null
+ | TypeCode.Char ->
+ this.ToChar null
+ | TypeCode.DateTime ->
+ this.ToDateTime null
+ | TypeCode.Decimal->
+ this.ToDecimal null
+ | TypeCode.Double ->
+ this.ToDouble null
+ | TypeCode.Int16 ->
+ this.ToInt16 null
+ | TypeCode.Int32 ->
+ this.ToInt32 null
+ | TypeCode.Int64 ->
+ this.ToInt64 null
+ | TypeCode.Object ->
+ if typeof.Equals conversionType then
+ this
+ else
+ raise (InvalidCastException $"Conversion to a {conversionType.Name} is not supported.")
+ | TypeCode.SByte ->
+ this.ToSByte null
+ | TypeCode.Single ->
+ this.ToSingle null
+ | TypeCode.String ->
+ this.ToString null
+ | TypeCode.UInt16 ->
+ this.ToUInt16 null
+ | TypeCode.UInt32 ->
+ this.ToUInt32 null
+ | TypeCode.UInt64 ->
+ this.ToUInt64 null
+ | _ ->
+ raise (InvalidCastException $"Conversion to {conversionType.Name} is not supported.")
+
+ member this.ToUInt16(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ raise (OverflowException $"{Int16.Parse(this.hexString, NumberStyles.HexNumber)} is outside the range of the UInt16 type.")
+ else
+ UInt16.Parse(this.hexString, NumberStyles.HexNumber)
+
+ member this.ToUInt32(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ raise (OverflowException $"{Int16.Parse(this.hexString, NumberStyles.HexNumber)} is outside the range of the UInt32 type.")
+ else
+ Convert.ToUInt32(this.hexString, 16)
+
+ member this.ToUInt64(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ raise (OverflowException $"{Int64.Parse(this.hexString, NumberStyles.HexNumber)} is outside the range of the UInt64 type.")
+ else
+ Convert.ToUInt64(this.hexString, 16)
+ //
+
+//
+let positiveValue = 32000us
+let negativeValue = -1s
+
+let mutable positiveString = HexString()
+positiveString.Sign <- Math.Sign positiveValue |> enum
+positiveString.Value <- positiveValue.ToString "X2"
+
+let mutable negativeString = HexString()
+negativeString.Sign <- sign negativeValue |> enum
+negativeString.Value <- negativeValue.ToString "X2"
+
+try
+ printfn $"0x{positiveString.Value} converts to {Convert.ToUInt16 positiveString}."
+with :? OverflowException ->
+ printfn $"{Int16.Parse(negativeString.Value, NumberStyles.HexNumber)} is outside the range of the UInt16 type."
+
+try
+ printfn $"0x{negativeString.Value} converts to {Convert.ToUInt16 negativeString}."
+with :? OverflowException ->
+ printfn $"{Int16.Parse(negativeString.Value, NumberStyles.HexNumber)} is outside the range of the UInt16 type."
+// The example displays the following output:
+// 0x7D00 converts to 32000.
+// -1 is outside the range of the UInt16 type.
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToUInt16/touint16_4.fs b/snippets/fsharp/System/Convert/ToUInt16/touint16_4.fs
new file mode 100644
index 00000000000..e295f01fcdb
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToUInt16/touint16_4.fs
@@ -0,0 +1,33 @@
+module touint16_4
+
+//
+open System
+open System.Globalization
+
+// Create a NumberFormatInfo object and set several of its
+// properties that apply to numbers.
+let provider = NumberFormatInfo()
+provider.PositiveSign <- "pos "
+provider.NegativeSign <- "neg "
+
+// Define an array of strings to convert to UInt16 values.
+let values =
+ [| "34567"; "+34567"; "pos 34567"; "34567."
+ "34567."; "65535"; "65535"; "65535" |]
+
+for value in values do
+ printf $"{value,-12} --> "
+ try
+ printfn $"{Convert.ToUInt16(value, provider),17}"
+ with :? FormatException as e ->
+ printfn $"{e.GetType().Name,17}"
+// The example displays the following output:
+// 34567 --> 34567
+// +34567 --> FormatException
+// pos 34567 --> 34567
+// 34567. --> FormatException
+// 34567. --> FormatException
+// 65535 --> 65535
+// 65535 --> 65535
+// 65535 --> 65535
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToUInt32/fs.fsproj b/snippets/fsharp/System/Convert/ToUInt32/fs.fsproj
new file mode 100644
index 00000000000..b35a101993b
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToUInt32/fs.fsproj
@@ -0,0 +1,12 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToUInt32/touint32_1.fs b/snippets/fsharp/System/Convert/ToUInt32/touint32_1.fs
new file mode 100644
index 00000000000..39330179eab
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToUInt32/touint32_1.fs
@@ -0,0 +1,314 @@
+module touint32_1
+
+open System
+
+let convertBoolean () =
+ //
+ let falseFlag = false
+ let trueFlag = true
+
+ printfn $"{falseFlag} converts to {Convert.ToInt32 falseFlag}."
+ printfn $"{trueFlag} converts to {Convert.ToInt32 trueFlag}."
+ // The example displays the following output:
+ // False converts to 0.
+ // True converts to 1.
+ //
+
+let convertByte () =
+ //
+ let bytes = [| Byte.MinValue; 14uy; 122uy; Byte.MaxValue |]
+
+ for byteValue in bytes do
+ let result = Convert.ToUInt16 byteValue
+ printfn $"Converted the {byteValue.GetType().Name} value '{byteValue}' to the {result.GetType().Name} value {result}."
+ // The example displays the following output:
+ // Converted the Byte value '0' to the UInt32 value 0.
+ // Converted the Byte value '14' to the UInt32 value 14.
+ // Converted the Byte value '122' to the UInt32 value 122.
+ // Converted the Byte value '255' to the UInt32 value 255.
+ //
+
+let convertChar () =
+ //
+ let chars =
+ [| 'a'; 'z'; '\u0007'; '\u03FF'; '\u7FFF'; '\uFFFE' |]
+
+ for ch in chars do
+ try
+ let result = Convert.ToUInt16 ch
+ printfn $"Converted the {ch.GetType().Name} value '{ch}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"Unable to convert u+{int ch:X4} to a UInt16."
+ // The example displays the following output:
+ // Converted the Char value 'a' to the UInt32 value 97.
+ // Converted the Char value 'z' to the UInt32 value 122.
+ // Converted the Char value '' to the UInt32 value 7.
+ // Converted the Char value '?' to the UInt32 value 1023.
+ // Converted the Char value '?' to the UInt32 value 32767.
+ // Converted the Char value '?' to the UInt32 value 65534.
+ //
+
+let convertDecimal () =
+ //
+ let numbers =
+ [| Decimal.MinValue; -1034.23m; -12m; 0m; 147m; 9214.16m; Decimal.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToUInt16 number
+ printfn $"Converted the {number.GetType().Name} value '{number}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"{number} is outside the range of the UInt32 type."
+ // The example displays the following output:
+ // -79228162514264337593543950335 is outside the range of the UInt32 type.
+ // -1034.23 is outside the range of the UInt32 type.
+ // -12 is outside the range of the UInt32 type.
+ // Converted the Decimal value '0' to the UInt32 value 0.
+ // Converted the Decimal value '147' to the UInt32 value 147.
+ // Converted the Decimal value '9214.16' to the UInt32 value 9214.
+ // 79228162514264337593543950335 is outside the range of the UInt32 type.
+ //
+
+let convertDouble () =
+ //
+ let numbers =
+ [| Double.MinValue; -1.38e10; -1023.299; -12.98
+ 0; 9.113e-16; 103.919; 17834.191; Double.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToUInt16 number
+ printfn $"Converted the {number.GetType().Name} value '{number}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"{number} is outside the range of the UInt32 type."
+ // The example displays the following output:
+ // -1.79769313486232E+308 is outside the range of the UInt32 type.
+ // -13800000000 is outside the range of the UInt32 type.
+ // -1023.299 is outside the range of the UInt32 type.
+ // -12.98 is outside the range of the UInt32 type.
+ // Converted the Double value '0' to the UInt32 value 0.
+ // Converted the Double value '9.113E-16' to the UInt32 value 0.
+ // Converted the Double value '103.919' to the UInt32 value 104.
+ // Converted the Double value '17834.191' to the UInt32 value 17834.
+ // 1.79769313486232E+308 is outside the range of the UInt32 type.
+ //
+
+let convertInt16 () =
+ //
+ let numbers = [| Int16.MinValue; -132s; 0s; 121s; 16103s; Int16.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToUInt16 number
+ printfn $"Converted the {number.GetType().Name} value '{number}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"The {number.GetType().Name} value {number} is outside the range of the UInt32 type."
+ // The example displays the following output:
+ // The Int16 value -32768 is outside the range of the UInt32 type.
+ // The Int16 value -132 is outside the range of the UInt32 type.
+ // Converted the Int16 value '0' to the UInt32 value 0.
+ // Converted the Int16 value '121' to the UInt32 value 121.
+ // Converted the Int16 value '16103' to the UInt32 value 16103.
+ // Converted the Int16 value '32767' to the UInt32 value 32767.
+ //
+
+let convertInt32 () =
+ //
+ let numbers = [| Int32.MinValue; -1; 0; 121; 340; Int32.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToUInt16 number
+ printfn $"Converted the {number.GetType().Name} value '{number}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn "The {number.GetType().Name} value {number} is outside the range of the UInt32 type."
+
+ // The example displays the following output:
+ // The Int32 value -2147483648 is outside the range of the UInt32 type.
+ // The Int32 value -1 is outside the range of the UInt32 type.
+ // Converted the Int32 value '0' to the UInt32 value 0.
+ // Converted the Int32 value '121' to the UInt32 value 121.
+ // Converted the Int32 value '340' to the UInt32 value 340.
+ // The Int32 value 2147483647 is outside the range of the UInt32 type.
+ //
+
+let convertInt64 () =
+ //
+ let numbers = [| Int64.MinValue; -1; 0; 121; 340; Int64.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToUInt16 number
+ printfn $"Converted the {number.GetType().Name} value '{number}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn "The {number.GetType().Name} value {number} is outside the range of the UInt32 type."
+ // The example displays the following output:
+ // The Int64 value -9223372036854775808 is outside the range of the UInt32 type.
+ // The Int64 value -1 is outside the range of the UInt32 type.
+ // Converted the Int64 value '0' to the UInt32 value 0.
+ // Converted the Int64 value '121' to the UInt32 value 121.
+ // Converted the Int64 value '340' to the UInt32 value 340.
+ // The Int64 value 9223372036854775807 is outside the range of the UInt32 type.
+ //
+
+let convertObject () =
+ //
+ let values: obj[] =
+ [| true; -12; 163; 935; 'x'; DateTime(2009, 5, 12)
+ "104"; "103.0"; "-1"; "1.00e2"; "One"; 1.00e2 |]
+
+ for value in values do
+ try
+ let result = Convert.ToUInt16 value
+ printfn $"Converted the {value.GetType().Name} value '{value}' to the {result.GetType().Name} value {result}."
+ with
+ | :? OverflowException ->
+ printfn $"The {value.GetType().Name} value {value} is outside the range of the UInt32 type."
+ | :? FormatException ->
+ printfn $"The {value.GetType().Name} value {value} is not in a recognizable format."
+ | :? InvalidCastException ->
+ printfn $"No conversion to a UInt16 exists for the {value.GetType().Name} value {value}."
+ // The example displays the following output:
+ // Converted the Boolean value 'True' to the UInt32 value 1.
+ // The Int32 value -12 is outside the range of the UInt32 type.
+ // Converted the Int32 value '163' to the UInt32 value 163.
+ // Converted the Int32 value '935' to the UInt32 value 935.
+ // Converted the Char value 'x' to the UInt32 value 120.
+ // No conversion to a UInt16 exists for the DateTime value 5/12/2009 12:00:00 AM.
+ // Converted the String value '104' to the UInt32 value 104.
+ // The String value 103.0 is not in a recognizable format.
+ // The String value -1 is outside the range of the UInt32 type.
+ // The String value 1.00e2 is not in a recognizable format.
+ // The String value One is not in a recognizable format.
+ // Converted the Double value '100' to the UInt32 value 100.
+ //
+
+let convertSByte () =
+ //
+ let numbers = [| SByte.MinValue; -1y; 0y; 10y; SByte.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToUInt16 number
+ printfn $"Converted the {number.GetType().Name} value '{number}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"{number} is outside the range of the UInt32 type."
+ // The example displays the following output:
+ // -128 is outside the range of the UInt32 type.
+ // -1 is outside the range of the UInt32 type.
+ // Converted the SByte value '0' to the UInt32 value 0.
+ // Converted the SByte value '10' to the UInt32 value 10.
+ // Converted the SByte value '127' to the UInt32 value 127.
+ //
+
+let convertSingle () =
+ //
+ let numbers =
+ [| Single.MinValue; -1.38e10f; -1023.299f; -12.98f
+ 0f; 9.113e-16f; 103.919f; 17834.191f; Single.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToUInt16 number
+ printfn $"Converted the {number.GetType().Name} value '{number}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"{number} is outside the range of the UInt32 type."
+ // The example displays the following output:
+ // -3.402823E+38 is outside the range of the UInt32 type.
+ // -1.38E+10 is outside the range of the UInt32 type.
+ // -1023.299 is outside the range of the UInt32 type.
+ // -12.98 is outside the range of the UInt32 type.
+ // Converted the Single value '0' to the UInt32 value 0.
+ // Converted the Single value '9.113E-16' to the UInt32 value 0.
+ // Converted the Single value '103.919' to the UInt32 value 104.
+ // Converted the Single value '17834.19' to the UInt32 value 17834.
+ // 3.402823E+38 is outside the range of the UInt32 type.
+ //
+
+let convertString () =
+ //
+ let values =
+ [| "1603"; "1,603"; "one"; "1.6e03"
+ "1.2e-02"; "-1326"; "1074122" |]
+
+ for value in values do
+ try
+ let result = Convert.ToUInt16 value
+ printfn $"Converted the {value.GetType().Name} value '{value}' to the {result.GetType().Name} value {result}."
+ with
+ | :? FormatException ->
+ printfn $"The {value.GetType().Name} value {value} is not in a recognizable format."
+ | :? OverflowException ->
+ printfn $"{value} is outside the range of the UInt32 type."
+ // The example displays the following output:
+ // Converted the String value '1603' to the UInt32 value 1603.
+ // The String value 1,603 is not in a recognizable format.
+ // The String value one is not in a recognizable format.
+ // The String value 1.6e03 is not in a recognizable format.
+ // The String value 1.2e-02 is not in a recognizable format.
+ // -1326 is outside the range of the UInt32 type.
+ // 1074122 is outside the range of the UInt32 type.
+ //
+
+let convertUInt16 () =
+ //
+ let numbers = [| UInt16.MinValue; 121us; 340us; UInt16.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToUInt16 number
+ printfn $"Converted the {number.GetType().Name} value '{number}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"The {number.GetType().Name} value {number} is outside the range of the UInt32 type."
+
+ // The example displays the following output:
+ // Converted the UInt16 value '0' to the UInt32 value 0.
+ // Converted the UInt16 value '121' to the UInt32 value 121.
+ // Converted the UInt16 value '340' to the UInt32 value 340.
+ // The UInt16 value 4294967295 is outside the range of the UInt32 type.
+ //
+
+let convertUInt64 () =
+ //
+ let numbers = [| UInt64.MinValue; 121uL; 340uL; UInt64.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToUInt16 number
+ printfn $"Converted the {number.GetType().Name} value '{number}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"The {number.GetType().Name} value {number} is outside the range of the UInt32 type."
+ // The example displays the following output:
+ // Converted the UInt64 value '0' to the UInt32 value 0.
+ // Converted the UInt64 value '121' to the UInt32 value 121.
+ // Converted the UInt64 value '340' to the UInt32 value 340.
+ // The UInt64 value 18446744073709551615 is outside the range of the UInt32 type.
+ //
+
+convertBoolean ()
+printfn "-----"
+convertByte ()
+printfn "-----"
+convertChar ()
+printfn "-----"
+convertDecimal ()
+printfn "-----"
+convertDouble ()
+printfn "----"
+convertInt16 ()
+printfn "-----"
+convertInt32 ()
+printfn "-----"
+convertInt64 ()
+printfn "-----"
+convertObject ()
+printfn "-----"
+convertSByte ()
+printfn "-----"
+convertSingle ()
+printfn "----"
+convertString()
+printfn "-----"
+convertUInt16 ()
+printfn "-----"
+convertUInt64 ()
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToUInt32/touint32_2.fs b/snippets/fsharp/System/Convert/ToUInt32/touint32_2.fs
new file mode 100644
index 00000000000..1afa97ee290
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToUInt32/touint32_2.fs
@@ -0,0 +1,39 @@
+module touint32_2
+
+//
+open System
+open System.Globalization
+
+// Create a NumberFormatInfo object and set several of its
+// properties that apply to numbers.
+let provider = NumberFormatInfo()
+provider.PositiveSign <- "pos "
+provider.NegativeSign <- "neg "
+
+// Define an array of numeric strings.
+let values =
+ [| "123456789"; "+123456789"; "pos 123456789"
+ "123456789."; "123,456,789"; "4294967295"
+ "4294967296"; "-1"; "neg 1" |]
+
+for value in values do
+ printf $"{value,-20} -->"
+
+ try
+ printfn $"{Convert.ToUInt32(value, provider),20}"
+ with
+ | :? FormatException ->
+ printfn "%20s" "Bad Format"
+ | :? OverflowException ->
+ printfn "%20s" "Numeric Overflow"
+// The example displays the following output:
+// 123456789 --> 123456789
+// +123456789 --> Bad Format
+// pos 123456789 --> 123456789
+// 123456789. --> Bad Format
+// 123,456,789 --> Bad Format
+// 4294967295 --> 4294967295
+// 4294967296 --> Numeric Overflow
+// -1 --> Bad Format
+// neg 1 --> Numeric Overflow
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToUInt32/touint32_3.fs b/snippets/fsharp/System/Convert/ToUInt32/touint32_3.fs
new file mode 100644
index 00000000000..e615bac2253
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToUInt32/touint32_3.fs
@@ -0,0 +1,32 @@
+module touint32_3
+
+//
+open System
+
+let hexStrings =
+ [| "80000000"; "0FFFFFFF"; "F0000000"; "00A3000"
+ "D"; "-13"; "9AC61"; "GAD"; "FFFFFFFFFF" |]
+
+for hexString in hexStrings do
+ printf $"{hexString,-12} --> "
+ try
+ let number = Convert.ToUInt32(hexString, 16)
+ printfn $"{number,18:N0}"
+ with
+ | :? FormatException ->
+ printfn "%18s" "Bad Format"
+ | :? OverflowException ->
+ printfn "%18s" "Numeric Overflow"
+ | :? ArgumentException ->
+ printfn "%18s" "Invalid in Base 16"
+// The example displays the following output:
+// 80000000 --> 2,147,483,648
+// 0FFFFFFF --> 268,435,455
+// F0000000 --> 4,026,531,840
+// 00A3000 --> 667,648
+// D --> 13
+// -13 --> Invalid in Base 16
+// 9AC61 --> 633,953
+// GAD --> Bad Format
+// FFFFFFFFFF --> Numeric Overflow
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToUInt32/touint32_4.fs b/snippets/fsharp/System/Convert/ToUInt32/touint32_4.fs
new file mode 100644
index 00000000000..dfb69b9357a
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToUInt32/touint32_4.fs
@@ -0,0 +1,209 @@
+module touint32_4
+
+//
+open System
+open System.Globalization
+open System.Text.RegularExpressions
+
+type SignBit =
+ | Negative = -1
+ | Zero = 0
+ | Positive = 1
+
+[]
+type HexString =
+ val mutable private hexString: string
+
+ val mutable Sign: SignBit
+
+ member this.Value
+ with get () = this.hexString
+ and set (value: string) =
+ if value.Trim().Length > 8 then
+ invalidArg "value" "The string representation of a 32 bit integer cannot have more than eight characters."
+ elif Regex.IsMatch(value, "([0-9,A-F]){1,8}", RegexOptions.IgnoreCase) |> not then
+ invalidArg "value" "The hexadecimal representation of a 32-bit integer contains invalid characters."
+ else
+ this.hexString <- value
+
+ interface IConvertible with
+ // IConvertible implementations.
+ member _.GetTypeCode() =
+ TypeCode.Object
+
+ member this.ToBoolean(provider: IFormatProvider) =
+ this.Sign <> SignBit.Zero
+
+ member this.ToByte(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ raise (OverflowException $"{Convert.ToInt32(this.hexString, 16)} is out of range of the Byte type.")
+ else
+ try
+ Byte.Parse(this.hexString, NumberStyles.HexNumber)
+ with :? OverflowException as e ->
+ raise (OverflowException($"{Convert.ToInt32(this.hexString, 16)} is out of range of the Byte type.", e) )
+
+ member this.ToChar(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ raise (OverflowException $"{Convert.ToInt32(this.hexString, 16)} is out of range of the Char type.")
+
+ try
+ let codePoint = UInt16.Parse(this.hexString, NumberStyles.HexNumber)
+ Convert.ToChar codePoint
+ with :? OverflowException as e ->
+ raise (OverflowException($"{Convert.ToInt32(this.hexString, 16)} is out of range of the Char type.", e) )
+
+ member _.ToDateTime(provider: IFormatProvider) =
+ raise (InvalidCastException "Hexadecimal to DateTime conversion is not supported.")
+
+ member this.ToDecimal(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ let hexValue = Int32.Parse(this.hexString, NumberStyles.HexNumber)
+ Convert.ToDecimal hexValue
+ else
+ let hexValue = UInt32.Parse(this.hexString, NumberStyles.HexNumber)
+ Convert.ToDecimal hexValue
+
+ member this.ToDouble(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ Convert.ToDouble(Int32.Parse(this.hexString, NumberStyles.HexNumber))
+ else
+ Convert.ToDouble(UInt32.Parse(this.hexString, NumberStyles.HexNumber))
+
+ member this.ToInt16(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ try
+ Convert.ToInt16(Int32.Parse(this.hexString, NumberStyles.HexNumber))
+ with :? OverflowException as e ->
+ raise (OverflowException($"{Convert.ToInt32(this.hexString, 16)} is out of range of the Int16 type.", e) )
+ else
+ try
+ Convert.ToInt16(UInt32.Parse(this.hexString, NumberStyles.HexNumber))
+ with :? OverflowException as e ->
+ raise (OverflowException($"{Convert.ToInt32(this.hexString, 16)} is out of range of the Int16 type.", e) )
+
+ member this.ToInt32(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ Int32.Parse(this.hexString, NumberStyles.HexNumber)
+ else
+ try
+ Convert.ToInt32(UInt32.Parse(this.hexString, NumberStyles.HexNumber))
+ with :? OverflowException as e ->
+ raise (OverflowException($"{Convert.ToInt32(this.hexString, 16)} is out of range of the Int32 type.", e) )
+
+ member this.ToInt64(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ Convert.ToInt64(Int32.Parse(this.hexString, NumberStyles.HexNumber))
+ else
+ Int64.Parse(this.hexString, NumberStyles.HexNumber)
+
+ member this.ToSByte(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ try
+ Convert.ToSByte(Int32.Parse(this.hexString, NumberStyles.HexNumber))
+ with :? OverflowException as e ->
+ raise (OverflowException($"{Int32.Parse(this.hexString, NumberStyles.HexNumber)} is outside the range of the SByte type.", e) )
+ else
+ try
+ Convert.ToSByte(UInt32.Parse(this.hexString, NumberStyles.HexNumber))
+ with :? OverflowException as e ->
+ raise (OverflowException($"{UInt32.Parse(this.hexString, NumberStyles.HexNumber)} is outside the range of the SByte type.", e) )
+
+ member this.ToSingle(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ Convert.ToSingle(Int32.Parse(this.hexString, NumberStyles.HexNumber))
+ else
+ Convert.ToSingle(UInt32.Parse(this.hexString, NumberStyles.HexNumber))
+
+ member this.ToString(provider: IFormatProvider) =
+ "0x" + this.hexString
+
+ member this.ToType(conversionType: Type, provider: IFormatProvider) =
+ let this = this :> IConvertible
+ match Type.GetTypeCode conversionType with
+ | TypeCode.Boolean ->
+ this.ToBoolean null
+ | TypeCode.Byte ->
+ this.ToByte null
+ | TypeCode.Char ->
+ this.ToChar null
+ | TypeCode.DateTime ->
+ this.ToDateTime null
+ | TypeCode.Decimal ->
+ this.ToDecimal null
+ | TypeCode.Double ->
+ this.ToDouble null
+ | TypeCode.Int16 ->
+ this.ToInt16 null
+ | TypeCode.Int32 ->
+ this.ToInt32 null
+ | TypeCode.Int64 ->
+ this.ToInt64 null
+ | TypeCode.Object ->
+ if typeof.Equals conversionType then
+ this
+ else
+ raise (InvalidCastException $"Conversion to a {conversionType.Name} is not supported.")
+ | TypeCode.SByte ->
+ this.ToSByte null
+ | TypeCode.Single ->
+ this.ToSingle null
+ | TypeCode.String ->
+ this.ToString null
+ | TypeCode.UInt16 ->
+ this.ToUInt16 null
+ | TypeCode.UInt32 ->
+ this.ToUInt32 null
+ | TypeCode.UInt64 ->
+ this.ToUInt64 null
+ | _ ->
+ raise (InvalidCastException $"Conversion to {conversionType.Name} is not supported.")
+
+ member this.ToUInt16(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ raise (OverflowException $"{Int32.Parse(this.hexString, NumberStyles.HexNumber)} is outside the range of the UInt16 type.")
+ else
+ try
+ Convert.ToUInt16(UInt32.Parse(this.hexString, NumberStyles.HexNumber))
+ with :? OverflowException as e ->
+ raise (OverflowException($"{Convert.ToInt32(this.hexString, 16)} is out of range of the UInt16 type.", e) )
+
+ member this.ToUInt32(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ raise (OverflowException $"{Int32.Parse(this.hexString, NumberStyles.HexNumber)} is outside the range of the UInt32 type.")
+ else
+ Convert.ToUInt32(this.hexString, 16)
+
+ member this.ToUInt64(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ raise (OverflowException $"{Int32.Parse(this.hexString, NumberStyles.HexNumber)} is outside the range of the UInt64 type.")
+ else
+ Convert.ToUInt64(this.hexString, 16)
+//
+
+//
+let positiveValue = 320000000u
+let negativeValue = -1
+
+let mutable positiveString = HexString()
+positiveString.Sign <- Math.Sign positiveValue |> enum
+positiveString.Value <- positiveValue.ToString "X4"
+
+let mutable negativeString = HexString()
+negativeString.Sign <- sign negativeValue |> enum
+negativeString.Value <- negativeValue.ToString "X4"
+
+try
+ printfn $"0x{positiveString.Value} converts to {Convert.ToUInt32 positiveString}."
+with :? OverflowException ->
+ printfn $"{Int32.Parse(positiveString.Value, NumberStyles.HexNumber)} is outside the range of the UInt32 type."
+
+try
+ printfn $"0x{negativeString.Value} converts to {Convert.ToUInt32 negativeString}."
+with :? OverflowException ->
+ printfn $"{Int32.Parse(negativeString.Value, NumberStyles.HexNumber)} is outside the range of the UInt32 type."
+// The example dosplays the following output:
+// 0x1312D000 converts to 320000000.
+// -1 is outside the range of the UInt32 type.
+//
+// Copied from /samples/snippets/csharp/System/Convert/ToUInt32/touint32_4.cs
diff --git a/snippets/fsharp/System/Convert/ToUInt64/fs.fsproj b/snippets/fsharp/System/Convert/ToUInt64/fs.fsproj
new file mode 100644
index 00000000000..42ab0457f88
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToUInt64/fs.fsproj
@@ -0,0 +1,12 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToUInt64/touint64_1.fs b/snippets/fsharp/System/Convert/ToUInt64/touint64_1.fs
new file mode 100644
index 00000000000..8a3ce87c8d3
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToUInt64/touint64_1.fs
@@ -0,0 +1,314 @@
+module touint64_1
+
+open System
+
+let convertBoolean () =
+ //
+ let falseFlag = false
+ let trueFlag = true
+
+ printfn $"{falseFlag} converts to {Convert.ToInt32 falseFlag}."
+ printfn $"{trueFlag} converts to {Convert.ToInt32 trueFlag}."
+ // The example displays the following output:
+ // False converts to 0.
+ // True converts to 1.
+ //
+
+let convertByte () =
+ //
+ let bytes = [| Byte.MinValue; 14uy; 122uy; Byte.MaxValue |]
+
+ for byteValue in bytes do
+ let result = Convert.ToUInt16 byteValue
+ printfn $"Converted the {byteValue.GetType().Name} value '{byteValue}' to the {result.GetType().Name} value {result}."
+ // The example displays the following output:
+ // Converted the Byte value '0' to the UInt64 value 0.
+ // Converted the Byte value '14' to the UInt64 value 14.
+ // Converted the Byte value '122' to the UInt64 value 122.
+ // Converted the Byte value '255' to the UInt64 value 255.
+ //
+
+let convertChar () =
+ //
+ let chars =
+ [| 'a'; 'z'; '\u0007'; '\u03FF'; '\u7FFF'; '\uFFFE' |]
+
+ for ch in chars do
+ try
+ let result = Convert.ToUInt16 ch
+ printfn $"Converted the {ch.GetType().Name} value '{ch}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"Unable to convert u+{int ch:X4} to a UInt16."
+ // The example displays the following output:
+ // Converted the Char value 'a' to the UInt64 value 97.
+ // Converted the Char value 'z' to the UInt64 value 122.
+ // Converted the Char value '' to the UInt64 value 7.
+ // Converted the Char value '?' to the UInt64 value 1023.
+ // Converted the Char value '?' to the UInt64 value 32767.
+ // Converted the Char value '?' to the UInt64 value 65534.
+ //
+
+let convertDecimal () =
+ //
+ let numbers =
+ [| Decimal.MinValue; -1034.23m; -12m; 0m; 147m; 9214.16m; Decimal.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToUInt16 number
+ printfn $"Converted the {number.GetType().Name} value '{number}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"{number} is outside the range of the UInt64 type."
+ // The example displays the following output:
+ // -79228162514264337593543950335 is outside the range of the UInt64 type.
+ // -1034.23 is outside the range of the UInt64 type.
+ // -12 is outside the range of the UInt64 type.
+ // Converted the Decimal value '0' to the UInt64 value 0.
+ // Converted the Decimal value '147' to the UInt64 value 147.
+ // Converted the Decimal value '9214.16' to the UInt64 value 9214.
+ // 79228162514264337593543950335 is outside the range of the UInt64 type.
+ //
+
+let convertDouble () =
+ //
+ let numbers =
+ [| Double.MinValue; -1.38e10; -1023.299; -12.98
+ 0; 9.113e-16; 103.919; 17834.191; Double.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToUInt16 number
+ printfn $"Converted the {number.GetType().Name} value '{number}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"{number} is outside the range of the UInt64 type."
+ // The example displays the following output:
+ // -1.79769313486232E+308 is outside the range of the UInt64 type.
+ // -13800000000 is outside the range of the UInt64 type.
+ // -1023.299 is outside the range of the UInt64 type.
+ // -12.98 is outside the range of the UInt64 type.
+ // Converted the Double value '0' to the UInt64 value 0.
+ // Converted the Double value '9.113E-16' to the UInt64 value 0.
+ // Converted the Double value '103.919' to the UInt64 value 104.
+ // Converted the Double value '17834.191' to the UInt64 value 17834.
+ // 1.79769313486232E+308 is outside the range of the UInt64 type.
+ //
+
+let convertInt16 () =
+ //
+ let numbers = [| Int16.MinValue; -132s; 0s; 121s; 16103s; Int16.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToUInt16 number
+ printfn $"Converted the {number.GetType().Name} value '{number}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"The {number.GetType().Name} value {number} is outside the range of the UInt64 type."
+ // The example displays the following output:
+ // The Int16 value -32768 is outside the range of the UInt64 type.
+ // The Int16 value -132 is outside the range of the UInt64 type.
+ // Converted the Int16 value '0' to the UInt64 value 0.
+ // Converted the Int16 value '121' to the UInt64 value 121.
+ // Converted the Int16 value '16103' to the UInt64 value 16103.
+ // Converted the Int16 value '32767' to the UInt64 value 32767.
+ //
+
+let convertInt32 () =
+ //
+ let numbers = [| Int32.MinValue; -1; 0; 121; 340; Int32.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToUInt16 number
+ printfn $"Converted the {number.GetType().Name} value '{number}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn "The {number.GetType().Name} value {number} is outside the range of the UInt64 type."
+
+ // The example displays the following output:
+ // The Int32 value -2147483648 is outside the range of the UInt64 type.
+ // The Int32 value -1 is outside the range of the UInt64 type.
+ // Converted the Int32 value '0' to the UInt64 value 0.
+ // Converted the Int32 value '121' to the UInt64 value 121.
+ // Converted the Int32 value '340' to the UInt64 value 340.
+ // The Int32 value 2147483647 is outside the range of the UInt64 type.
+ //
+
+let convertInt64 () =
+ //
+ let numbers = [| Int64.MinValue; -1; 0; 121; 340; Int64.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToUInt16 number
+ printfn $"Converted the {number.GetType().Name} value '{number}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn "The {number.GetType().Name} value {number} is outside the range of the UInt64 type."
+ // The example displays the following output:
+ // The Int64 value -9223372036854775808 is outside the range of the UInt64 type.
+ // The Int64 value -1 is outside the range of the UInt64 type.
+ // Converted the Int64 value '0' to the UInt64 value 0.
+ // Converted the Int64 value '121' to the UInt64 value 121.
+ // Converted the Int64 value '340' to the UInt64 value 340.
+ // The Int64 value 9223372036854775807 is outside the range of the UInt64 type.
+ //
+
+let convertObject () =
+ //
+ let values: obj[] =
+ [| true; -12; 163; 935; 'x'; DateTime(2009, 5, 12)
+ "104"; "103.0"; "-1"; "1.00e2"; "One"; 1.00e2 |]
+
+ for value in values do
+ try
+ let result = Convert.ToUInt16 value
+ printfn $"Converted the {value.GetType().Name} value '{value}' to the {result.GetType().Name} value {result}."
+ with
+ | :? OverflowException ->
+ printfn $"The {value.GetType().Name} value {value} is outside the range of the UInt64 type."
+ | :? FormatException ->
+ printfn $"The {value.GetType().Name} value {value} is not in a recognizable format."
+ | :? InvalidCastException ->
+ printfn $"No conversion to a UInt16 exists for the {value.GetType().Name} value {value}."
+ // The example displays the following output:
+ // Converted the Boolean value 'True' to the UInt64 value 1.
+ // The Int32 value -12 is outside the range of the UInt64 type.
+ // Converted the Int32 value '163' to the UInt64 value 163.
+ // Converted the Int32 value '935' to the UInt64 value 935.
+ // Converted the Char value 'x' to the UInt64 value 120.
+ // No conversion to a UInt16 exists for the DateTime value 5/12/2009 12:00:00 AM.
+ // Converted the String value '104' to the UInt64 value 104.
+ // The String value 103.0 is not in a recognizable format.
+ // The String value -1 is outside the range of the UInt64 type.
+ // The String value 1.00e2 is not in a recognizable format.
+ // The String value One is not in a recognizable format.
+ // Converted the Double value '100' to the UInt64 value 100.
+ //
+
+let convertSByte () =
+ //
+ let numbers = [| SByte.MinValue; -1y; 0y; 10y; SByte.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToUInt16 number
+ printfn $"Converted the {number.GetType().Name} value '{number}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"{number} is outside the range of the UInt64 type."
+ // The example displays the following output:
+ // -128 is outside the range of the UInt64 type.
+ // -1 is outside the range of the UInt64 type.
+ // Converted the SByte value '0' to the UInt64 value 0.
+ // Converted the SByte value '10' to the UInt64 value 10.
+ // Converted the SByte value '127' to the UInt64 value 127.
+ //
+
+let convertSingle () =
+ //
+ let numbers =
+ [| Single.MinValue; -1.38e10f; -1023.299f; -12.98f
+ 0f; 9.113e-16f; 103.919f; 17834.191f; Single.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToUInt16 number
+ printfn $"Converted the {number.GetType().Name} value '{number}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"{number} is outside the range of the UInt64 type."
+ // The example displays the following output:
+ // -3.402823E+38 is outside the range of the UInt64 type.
+ // -1.38E+10 is outside the range of the UInt64 type.
+ // -1023.299 is outside the range of the UInt64 type.
+ // -12.98 is outside the range of the UInt64 type.
+ // Converted the Single value '0' to the UInt64 value 0.
+ // Converted the Single value '9.113E-16' to the UInt64 value 0.
+ // Converted the Single value '103.919' to the UInt64 value 104.
+ // Converted the Single value '17834.19' to the UInt64 value 17834.
+ // 3.402823E+38 is outside the range of the UInt64 type.
+ //
+
+let convertString () =
+ //
+ let values =
+ [| "1603"; "1,603"; "one"; "1.6e03"
+ "1.2e-02"; "-1326"; "1074122" |]
+
+ for value in values do
+ try
+ let result = Convert.ToUInt16 value
+ printfn $"Converted the {value.GetType().Name} value '{value}' to the {result.GetType().Name} value {result}."
+ with
+ | :? FormatException ->
+ printfn $"The {value.GetType().Name} value {value} is not in a recognizable format."
+ | :? OverflowException ->
+ printfn $"{value} is outside the range of the UInt64 type."
+ // The example displays the following output:
+ // Converted the String value '1603' to the UInt64 value 1603.
+ // The String value 1,603 is not in a recognizable format.
+ // The String value one is not in a recognizable format.
+ // The String value 1.6e03 is not in a recognizable format.
+ // The String value 1.2e-02 is not in a recognizable format.
+ // -1326 is outside the range of the UInt64 type.
+ // 1074122 is outside the range of the UInt64 type.
+ //
+
+let convertUInt16 () =
+ //
+ let numbers = [| UInt16.MinValue; 121us; 340us; UInt16.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToUInt16 number
+ printfn $"Converted the {number.GetType().Name} value '{number}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"The {number.GetType().Name} value {number} is outside the range of the UInt64 type."
+
+ // The example displays the following output:
+ // Converted the UInt16 value '0' to the UInt64 value 0.
+ // Converted the UInt16 value '121' to the UInt64 value 121.
+ // Converted the UInt16 value '340' to the UInt64 value 340.
+ // The UInt16 value 65535 is outside the range of the UInt64 type.
+ //
+
+let convertUInt32 () =
+ //
+ let numbers = [| UInt32.MinValue; 121u; 340u; UInt32.MaxValue |]
+
+ for number in numbers do
+ try
+ let result = Convert.ToUInt16 number
+ printfn $"Converted the {number.GetType().Name} value '{number}' to the {result.GetType().Name} value {result}."
+ with :? OverflowException ->
+ printfn $"The {number.GetType().Name} value {number} is outside the range of the UInt64 type."
+ // The example displays the following output:
+ // Converted the UInt32 value '0' to the UInt64 value 0.
+ // Converted the UInt64 value '121' to the UInt64 value 121.
+ // Converted the UInt64 value '340' to the UInt64 value 340.
+ // The UInt32 value 4294967295 is outside the range of the UInt64 type.
+ //
+
+convertBoolean ()
+printfn "-----"
+convertByte ()
+printfn "-----"
+convertChar ()
+printfn "-----"
+convertDecimal ()
+printfn "-----"
+convertDouble ()
+printfn "----"
+convertInt16 ()
+printfn "-----"
+convertInt32 ()
+printfn "-----"
+convertInt64 ()
+printfn "-----"
+convertObject ()
+printfn "-----"
+convertSByte ()
+printfn "-----"
+convertSingle ()
+printfn "----"
+convertString()
+printfn "-----"
+convertUInt16 ()
+printfn "-----"
+convertUInt32 ()
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToUInt64/touint64_2.fs b/snippets/fsharp/System/Convert/ToUInt64/touint64_2.fs
new file mode 100644
index 00000000000..71b4d27bd0a
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToUInt64/touint64_2.fs
@@ -0,0 +1,39 @@
+module touint64_2
+
+//
+open System
+open System.Globalization
+
+// Create a NumberFormatInfo object and set several properties.
+let provider = NumberFormatInfo()
+provider.PositiveSign <- "pos "
+provider.NegativeSign <- "neg "
+
+// Define an array of numeric strings.
+let values =
+ [| "123456789012"; "+123456789012"
+ "pos 123456789012"; "123456789012."
+ "123,456,789,012"; "18446744073709551615"
+ "18446744073709551616"; "neg 1"; "-1" |]
+
+// Convert the strings using the format provider.
+for value in values do
+ printf $"{value,-20} --> "
+ try
+ printfn $"{Convert.ToUInt64(value, provider),20}"
+ with
+ | :? FormatException ->
+ printfn "%20s" "Invalid Format"
+ | :? OverflowException ->
+ printfn "%20s" "Numeric Overflow"
+// The example displays the following output:
+// 123456789012 --> 123456789012
+// +123456789012 --> Invalid Format
+// pos 123456789012 --> 123456789012
+// 123456789012. --> Invalid Format
+// 123,456,789,012 --> Invalid Format
+// 18446744073709551615 --> 18446744073709551615
+// 18446744073709551616 --> Numeric Overflow
+// neg 1 --> Numeric Overflow
+// -1 --> Invalid Format
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToUInt64/touint64_3.fs b/snippets/fsharp/System/Convert/ToUInt64/touint64_3.fs
new file mode 100644
index 00000000000..ce1ee994d62
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToUInt64/touint64_3.fs
@@ -0,0 +1,34 @@
+module touint64
+
+//
+open System
+
+let hexStrings =
+ [| "8000000000000000"; "0FFFFFFFFFFFFFFF"
+ "F000000000000000"; "00A3000000000000"
+ "D"; "-13"; "9AC61"; "GAD"
+ "FFFFFFFFFFFFFFFFF" |]
+
+for hexString in hexStrings do
+ printf $"{hexString,-18} --> "
+ try
+ let number = Convert.ToUInt64(hexString, 16)
+ printfn $"{number,26:N0}"
+ with
+ | :? FormatException ->
+ printfn "%26s" "Bad Format"
+ | :? OverflowException ->
+ printfn "%26s" "Numeric Overflow"
+ | :? ArgumentException ->
+ printfn "%26s" "Invalid in Base 16"
+// The example displays the following output:
+// 8000000000000000 --> 9,223,372,036,854,775,808
+// 0FFFFFFFFFFFFFFF --> 1,152,921,504,606,846,975
+// F000000000000000 --> 17,293,822,569,102,704,640
+// 00A3000000000000 --> 45,880,421,203,836,928
+// D --> 13
+// -13 --> Invalid in Base 16
+// 9AC61 --> 633,953
+// GAD --> Bad Format
+// FFFFFFFFFFFFFFFFF --> Numeric Overflow
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/Convert/ToUInt64/touint64_4.fs b/snippets/fsharp/System/Convert/ToUInt64/touint64_4.fs
new file mode 100644
index 00000000000..cb1474836e3
--- /dev/null
+++ b/snippets/fsharp/System/Convert/ToUInt64/touint64_4.fs
@@ -0,0 +1,215 @@
+module touint64_4
+
+//
+open System
+open System.Globalization
+open System.Text.RegularExpressions
+
+type SignBit =
+ | Negative = -1
+ | Zero = 0
+ | Positive = 1
+
+[]
+type HexString =
+ val mutable private hexString: string
+
+ val mutable Sign: SignBit
+
+ member this.Value
+ with get () = this.hexString
+ and set (value: string) =
+ if value.Trim().Length > 16 then
+ invalidArg "value" "The hexadecimal representation of a 64-bit integer cannot have more than 16 characters."
+ elif Regex.IsMatch(value, "([0-9,A-F]){1,8}", RegexOptions.IgnoreCase) |> not then
+ invalidArg "value" "The hexadecimal representation of a 64-bit integer contains invalid characters."
+ else
+ this.hexString <- value
+
+ // IConvertible implementations.
+ interface IConvertible with
+ member _.GetTypeCode() =
+ TypeCode.Object
+
+ member this.ToBoolean(provider: IFormatProvider) =
+ this.Sign <> SignBit.Zero
+
+ member this.ToByte(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ raise (OverflowException $"{Convert.ToInt64(this.hexString, 16)} is out of range of the Byte type.")
+ try
+ Byte.Parse(this.hexString, NumberStyles.HexNumber)
+ with :? OverflowException as e ->
+ raise (OverflowException($"{Convert.ToUInt64(this.hexString, 16)} is out of range of the Byte type.", e) )
+
+ member this.ToChar(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ raise (OverflowException $"{Convert.ToInt64(this.hexString, 16)} is out of range of the Char type.")
+ try
+ let codePoint = UInt16.Parse(this.hexString, NumberStyles.HexNumber)
+ Convert.ToChar codePoint
+ with :? OverflowException ->
+ raise (OverflowException $"{Convert.ToUInt64(this.hexString, 16)} is out of range of the Char type.")
+
+ member this.ToDateTime(provider: IFormatProvider) =
+ raise (InvalidCastException "Hexadecimal to DateTime conversion is not supported.")
+
+ member this.ToDecimal(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ let hexValue = Int64.Parse(this.hexString, NumberStyles.HexNumber)
+ Convert.ToDecimal hexValue
+ else
+ let hexValue = UInt64.Parse(this.hexString, NumberStyles.HexNumber)
+ Convert.ToDecimal hexValue
+
+ member this.ToDouble(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ Convert.ToDouble(Int64.Parse(this.hexString, NumberStyles.HexNumber))
+ else
+ Convert.ToDouble(UInt64.Parse(this.hexString, NumberStyles.HexNumber))
+
+ member this.ToInt16(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ try
+ Convert.ToInt16(Int64.Parse(this.hexString, NumberStyles.HexNumber))
+ with :? OverflowException as e ->
+ raise (OverflowException($"{Convert.ToInt64(this.hexString, 16)} is out of range of the Int16 type.", e) )
+ else
+ try
+ Convert.ToInt16(UInt64.Parse(this.hexString, NumberStyles.HexNumber))
+ with :? OverflowException as e ->
+ raise (OverflowException($"{Convert.ToUInt64(this.hexString, 16)} is out of range of the Int16 type.", e) )
+
+ member this.ToInt32(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ try
+ Convert.ToInt32(Int64.Parse(this.hexString, NumberStyles.HexNumber))
+ with :? OverflowException as e ->
+ raise (OverflowException($"{Convert.ToUInt64(this.hexString, 16)} is out of range of the Int32 type.", e) )
+ else
+ try
+ Convert.ToInt32(UInt64.Parse(this.hexString, NumberStyles.HexNumber))
+ with :? OverflowException as e ->
+ raise (OverflowException($"{Convert.ToUInt64(this.hexString, 16)} is out of range of the Int32 type.", e) )
+
+ member this.ToInt64(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ Int64.Parse(this.hexString, NumberStyles.HexNumber)
+ else
+ try
+ Convert.ToInt64(UInt64.Parse(this.hexString, NumberStyles.HexNumber))
+ with :? OverflowException as e ->
+ raise (OverflowException($"{Convert.ToUInt64(this.hexString, 16)} is out of range of the Int64 type.", e) )
+
+ member this.ToSByte(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ try
+ Convert.ToSByte(Int64.Parse(this.hexString, NumberStyles.HexNumber))
+ with :? OverflowException as e ->
+ raise (OverflowException($"{Int64.Parse(this.hexString, NumberStyles.HexNumber)} is outside the range of the SByte type.", e) )
+ else
+ try
+ Convert.ToSByte(UInt64.Parse(this.hexString, NumberStyles.HexNumber))
+ with :? OverflowException as e ->
+ raise (OverflowException($"{UInt64.Parse(this.hexString, NumberStyles.HexNumber)} is outside the range of the SByte type.", e) )
+
+ member this.ToSingle(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ Convert.ToSingle(Int64.Parse(this.hexString, NumberStyles.HexNumber))
+ else
+ Convert.ToSingle(UInt64.Parse(this.hexString, NumberStyles.HexNumber))
+
+ member this.ToString(provider: IFormatProvider) =
+ "0x" + this.hexString
+
+ member this.ToType(conversionType: Type, provider: IFormatProvider) =
+ let this = this :> IConvertible
+ match Type.GetTypeCode conversionType with
+ | TypeCode.Boolean ->
+ this.ToBoolean null
+ | TypeCode.Byte ->
+ this.ToByte null
+ | TypeCode.Char ->
+ this.ToChar null
+ | TypeCode.DateTime ->
+ this.ToDateTime null
+ | TypeCode.Decimal ->
+ this.ToDecimal null
+ | TypeCode.Double ->
+ this.ToDouble null
+ | TypeCode.Int16 ->
+ this.ToInt16 null
+ | TypeCode.Int32 ->
+ this.ToInt32 null
+ | TypeCode.Int64 ->
+ this.ToInt64 null
+ | TypeCode.Object ->
+ if typeof.Equals conversionType then
+ this
+ else
+ raise (InvalidCastException $"Conversion to a {conversionType.Name} is not supported.")
+ | TypeCode.SByte ->
+ this.ToSByte null
+ | TypeCode.Single ->
+ this.ToSingle null
+ | TypeCode.String ->
+ this.ToString null
+ | TypeCode.UInt16 ->
+ this.ToUInt16 null
+ | TypeCode.UInt32 ->
+ this.ToUInt32 null
+ | TypeCode.UInt64 ->
+ this.ToUInt64 null
+ | _ ->
+ raise (InvalidCastException $"Conversion to {conversionType.Name} is not supported.")
+
+ member this.ToUInt16(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ raise (OverflowException $"{Int64.Parse(this.hexString, NumberStyles.HexNumber)} is outside the range of the UInt16 type.")
+ else
+ try
+ Convert.ToUInt16(UInt64.Parse(this.hexString, NumberStyles.HexNumber))
+ with :? OverflowException as e ->
+ raise (OverflowException($"{Convert.ToUInt64(this.hexString, 16)} is out of range of the UInt16 type.", e) )
+
+ member this.ToUInt32(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ raise (OverflowException $"{Int64.Parse(this.hexString, NumberStyles.HexNumber)} is outside the range of the UInt32 type.")
+ else
+ try
+ Convert.ToUInt32(UInt64.Parse(this.hexString, NumberStyles.HexNumber))
+ with :? OverflowException ->
+ raise (OverflowException $"{UInt64.Parse(this.hexString, NumberStyles.HexNumber)} is outside the range of the UInt32 type.")
+
+ member this.ToUInt64(provider: IFormatProvider) =
+ if this.Sign = SignBit.Negative then
+ raise (OverflowException $"{Int64.Parse(this.hexString, NumberStyles.HexNumber)} is outside the range of the UInt64 type.")
+ else
+ Convert.ToUInt64(this.hexString, 16)
+//
+
+//
+let positiveValue = UInt64.MaxValue - 100000uL
+let negativeValue = -1L
+
+let mutable positiveString = HexString()
+positiveString.Sign <- Math.Sign(decimal positiveValue) |> enum
+positiveString.Value <- positiveValue.ToString "X"
+
+let mutable negativeString = HexString()
+negativeString.Sign <- sign negativeValue |> enum
+negativeString.Value <- negativeValue.ToString "X"
+
+try
+ printfn $"0x{positiveString.Value} converts to {Convert.ToUInt64 positiveString}."
+with :? OverflowException ->
+ printfn $"{Int64.Parse(positiveString.Value, NumberStyles.HexNumber)} is outside the range of the UInt64 type."
+
+try
+ printfn $"0x{negativeString.Value} converts to {Convert.ToUInt64 negativeString}."
+with :? OverflowException ->
+ printfn $"{Int64.Parse(negativeString.Value, NumberStyles.HexNumber)} is outside the range of the UInt64 type."
+// The example displays the following output:
+// 0xFFFFFFFFFFFE795F converts to 18446744073709451615.
+// -1 is outside the range of the UInt64 type.
+//
\ No newline at end of file
diff --git a/xml/System/Convert.xml b/xml/System/Convert.xml
index 7f5c5d636a3..628a3abba3c 100644
--- a/xml/System/Convert.xml
+++ b/xml/System/Convert.xml
@@ -121,6 +121,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert/CPP/NonDecimal1.cpp" id="Snippet2":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/Overview/NonDecimal1.cs" interactive="try-dotnet" id="Snippet2":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/Overview/NonDecimal1.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert/VB/NonDecimal1.vb" id="Snippet2":::
@@ -174,6 +175,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert/CPP/converter.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/Overview/converter.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/Overview/converter.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert/VB/converter.vb" id="Snippet1":::
]]>
@@ -275,6 +277,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/convertchangetype/CPP/convertchangetype.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ChangeType/convertchangetype.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ChangeType/convertchangetype.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/convertchangetype/VB/convertchangetype.vb" id="Snippet1":::
]]>
@@ -298,11 +301,13 @@
The method can convert an enumeration value to another type. However, it cannot convert another type to an enumeration value, even if the source type is the underlying type of the enumeration. To convert a type to an enumeration value, use a casting operator (in C#) or a conversion function (in Visual Basic). The following example illustrates the conversion to and from a Continent enumeration value.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ChangeType/changetype_enum2.cs" interactive="try-dotnet" id="Snippet5":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ChangeType/changetype_enum2.fs" id="Snippet5":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.changetype/vb/changetype_enum2.vb" id="Snippet5":::
The method can convert a nullable type to another type. However, it cannot convert another type to a value of a nullable type, even if is the underlying type of the .To perform the conversion, you can use a casting operator (in C#) or a conversion function (in Visual Basic). The following example illustrates the conversion to and from a nullable type.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ChangeType/changetype_nullable.cs" interactive="try-dotnet" id="Snippet7":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ChangeType/changetype_nullable.fs" id="Snippet7":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.changetype/vb/changetype_nullable.vb" id="Snippet7":::
@@ -376,6 +381,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.convert.changetype/cpp/changetype_01.cpp" id="Snippet2":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ChangeType/changetype01.cs" id="Snippet2":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ChangeType/changetype01.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.changetype/vb/changetype01.vb" id="Snippet2":::
]]>
@@ -473,12 +479,14 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.convert.changetype/cpp/changetype03.cpp" id="Snippet3":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ChangeType/changetype03.cs" id="Snippet3":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ChangeType/changetype03.fs" id="Snippet3":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.changetype/vb/changetype03.vb" id="Snippet3":::
The following example creates an instance of the `Temperature` class and calls the method to convert it to the basic numeric types supported by .NET and to a . It illustrates that the method wraps a call to the source type's implementation.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.convert.changetype/cpp/changetype03.cpp" id="Snippet4":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ChangeType/changetype03.cs" id="Snippet4":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ChangeType/changetype03.fs" id="Snippet4":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.changetype/vb/changetype03.vb" id="Snippet4":::
]]>
@@ -502,11 +510,13 @@
The method can convert an enumeration value to another type. However, it cannot convert another type to an enumeration value, even if the source type is the underlying type of the enumeration. To convert a type to an enumeration value, use a casting operator (in C#) or a conversion function (in Visual Basic). The following example illustrates the conversion to and from a Continent enumeration value.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ChangeType/changetype_enum2.cs" interactive="try-dotnet" id="Snippet5":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ChangeType/changetype_enum2.fs" id="Snippet5":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.changetype/vb/changetype_enum2.vb" id="Snippet5":::
The method can convert a nullable type to another type. However, it cannot convert another type to a value of a nullable type, even if is the underlying type of the . To perform the conversion, you can use a casting operator (in C#) or a conversion function (in Visual Basic). The following example illustrates the conversion to and from a nullable type.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ChangeType/changetype_nullable_1.cs" interactive="try-dotnet" id="Snippet8":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ChangeType/changetype_nullable_1.fs" id="Snippet8":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.changetype/vb/changetype_nullable_1.vb" id="Snippet8":::
@@ -584,6 +594,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.convert.changetype/cpp/changetype00.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ChangeType/changetype00.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ChangeType/changetype00.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.changetype/vb/changetype00.vb" id="Snippet1":::
]]>
@@ -648,6 +659,7 @@
The field is equivalent to , as the following example shows.
:::code language="csharp" source="~/snippets/csharp/System/Convert/DBNull/dbnull1.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/DBNull/dbnull1.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.dbnull/vb/dbnull1.vb" id="Snippet1":::
]]>
@@ -730,6 +742,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/System.Convert UUEncodeDecode functions/CPP/class1.cpp" id="Snippet3":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/FromBase64CharArray/class1.cs" id="Snippet3":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/FromBase64CharArray/class1.fs" id="Snippet3":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Convert UUEncodeDecode functions/VB/class1.vb" id="Snippet3":::
The following example demonstrates the and methods. The input is divided into groups of three bytes (24 bits) each. Consequently, each group consists of four 6-bit numbers where each number ranges from decimal 0 to 63. In this example, there are 85 3-byte groups with one byte remaining. The first group consists of the hexadecimal values 00, 01, and 02, which yield four 6-bit values equal to decimal 0, 0, 4, and 2. Those four values correspond to the base-64 digits, "A", "A", "E", and "C", at the beginning of the output.
@@ -738,6 +751,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/convert.tobase64chararray/CPP/tb64ca.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/FromBase64CharArray/tb64ca.cs" interactive="try-dotnet" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/FromBase64CharArray/tb64ca.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/convert.tobase64chararray/VB/tb64ca.vb" id="Snippet1":::
]]>
@@ -828,11 +842,13 @@
The following example uses the method to convert a byte array to a UUencoded (base-64) string, and then calls the method to restore the original byte array.
:::code language="csharp" source="~/snippets/csharp/System/Base64FormattingOptions/Overview/ToBase64String2.cs" interactive="try-dotnet" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Base64FormattingOptions/Overview/ToBase64String2.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Convert.ToBase64String/vb/ToBase64String2.vb" id="Snippet1":::
The following is a more complex example that creates a 20-element array of 32-bit integers. It then uses the method to convert each element into a byte array, which it stores in the appropriate position in a buffer by calling the method. This buffer is then passed to the method to create a UUencoded (base-64) string. It then calls the method to decode the UUencoded string, and calls the method to convert each set of four bytes (the size of a 32-bit integer) to an integer. The output from the example shows that the original array has been successfully restored.
:::code language="csharp" source="~/snippets/csharp/System/Base64FormattingOptions/Overview/ToBase64String.cs" interactive="try-dotnet" id="Snippet2":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Base64FormattingOptions/Overview/ToBase64String.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Convert.ToBase64String/vb/ToBase64String.vb" id="Snippet2":::
]]>
@@ -1021,6 +1037,7 @@
The method tests whether the `value` parameter is equal to . It is equivalent to the following code:
:::code language="csharp" source="~/snippets/csharp/System/Convert/IsDBNull/Form1.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/IsDBNull/Form1.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.IsDBNull/vb/Form1.vb" id="Snippet1":::
> [!NOTE]
@@ -1032,6 +1049,7 @@
The following example uses a object to retrieve survey data from a database. It assigns each row's field values to an array, and then passes each array element to the method. If the method returns `true`, the example assigns the string "NA" to the array element. The array is then added to the collection of a control.
:::code language="csharp" source="~/snippets/csharp/System/Convert/IsDBNull/Form1.cs" id="Snippet2":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/IsDBNull/Form1.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.IsDBNull/vb/Form1.vb" id="Snippet2":::
]]>
@@ -1125,6 +1143,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/System.Convert UUEncodeDecode functions/CPP/class1.cpp" id="Snippet2":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/FromBase64CharArray/class1.cs" id="Snippet2":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/FromBase64CharArray/class1.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Convert UUEncodeDecode functions/VB/class1.vb" id="Snippet2":::
]]>
@@ -1230,6 +1249,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/convert.tobase64chararray/CPP/tb64ca.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/FromBase64CharArray/tb64ca.cs" interactive="try-dotnet" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/FromBase64CharArray/tb64ca.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/convert.tobase64chararray/VB/tb64ca.vb" id="Snippet1":::
]]>
@@ -1329,11 +1349,13 @@
The following example uses the method to convert a byte array to a UUencoded (base-64) string, and then calls the method to restore the original byte array.
:::code language="csharp" source="~/snippets/csharp/System/Base64FormattingOptions/Overview/ToBase64String2.cs" interactive="try-dotnet" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Base64FormattingOptions/Overview/ToBase64String2.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Convert.ToBase64String/vb/ToBase64String2.vb" id="Snippet1":::
The following is a more complex example that creates a 20-element array of 32-bit integers. It then uses the method to convert each element into a byte array, which it stores in the appropriate position in a buffer by calling the method. This buffer is then passed to the method to create a UUencoded (base-64) string. It then calls the method to decode the UUencoded string, and calls the method to convert each set of four bytes (the size of a 32-bit integer) to an integer. The output from the example shows that the original array has been successfully restored.
:::code language="csharp" source="~/snippets/csharp/System/Base64FormattingOptions/Overview/ToBase64String.cs" interactive="try-dotnet" id="Snippet2":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Base64FormattingOptions/Overview/ToBase64String.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Convert.ToBase64String/vb/ToBase64String.vb" id="Snippet2":::
]]>
@@ -1412,6 +1434,7 @@
The following example calls the with a argument to insert line breaks in the string that is produced by encoding a 100-element byte array.
:::code language="csharp" source="~/snippets/csharp/System/Base64FormattingOptions/Overview/ToBase64String3.cs" interactive="try-dotnet" id="Snippet3":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Base64FormattingOptions/Overview/ToBase64String3.fs" id="Snippet3":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Convert.ToBase64String/vb/ToBase64String3.vb" id="Snippet3":::
As the output from the example shows, the succeeds in restoring the original byte array; the line break characters are ignored during the conversion.
@@ -1624,6 +1647,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/convert.tobase64string/CPP/tb64s.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBase64String/tb64s.cs" interactive="try-dotnet" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBase64String/tb64s.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/convert.tobase64string/VB/tb64s.vb" id="Snippet1":::
]]>
@@ -1756,6 +1780,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert.ToBoolean/cpp/toboolean2.cpp" id="Snippet12":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/toboolean2.cs" interactive="try-dotnet-method" id="Snippet12":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/toboolean2.fs" id="Snippet12":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToBoolean/vb/toboolean2.vb" id="Snippet12":::
]]>
@@ -1858,6 +1883,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert Snippets/CPP/system.convert snippet.cpp" id="Snippet20":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/system.convert snippet.cs" id="Snippet20":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/system.convert snippet.fs" id="Snippet20":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert Snippets/VB/system.convert snippet.vb" id="Snippet20":::
]]>
@@ -1918,6 +1944,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert.ToBoolean/cpp/toboolean2.cpp" id="Snippet2":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/toboolean2.cs" interactive="try-dotnet-method" id="Snippet2":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/toboolean2.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToBoolean/vb/toboolean2.vb" id="Snippet2":::
]]>
@@ -1978,6 +2005,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert Snippets/CPP/system.convert snippet.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/system.convert snippet.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/system.convert snippet.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert Snippets/VB/system.convert snippet.vb" id="Snippet1":::
]]>
@@ -2038,6 +2066,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert.ToBoolean/cpp/toboolean2.cpp" id="Snippet3":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/toboolean2.cs" interactive="try-dotnet-method" id="Snippet3":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/toboolean2.fs" id="Snippet3":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToBoolean/vb/toboolean2.vb" id="Snippet3":::
]]>
@@ -2098,6 +2127,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert.ToBoolean/cpp/toboolean2.cpp" id="Snippet4":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/toboolean2.cs" interactive="try-dotnet-method" id="Snippet4":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/toboolean2.fs" id="Snippet4":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToBoolean/vb/toboolean2.vb" id="Snippet4":::
]]>
@@ -2158,6 +2188,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert.ToBoolean/cpp/toboolean2.cpp" id="Snippet5":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/toboolean2.cs" interactive="try-dotnet-method" id="Snippet5":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/toboolean2.fs" id="Snippet5":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToBoolean/vb/toboolean2.vb" id="Snippet5":::
]]>
@@ -2219,6 +2250,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert.ToBoolean/cpp/toboolean2.cpp" id="Snippet11":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/toboolean2.cs" interactive="try-dotnet-method" id="Snippet11":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/toboolean2.fs" id="Snippet11":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToBoolean/vb/toboolean2.vb" id="Snippet11":::
]]>
@@ -2293,6 +2325,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert.ToBoolean/cpp/toboolean2.cpp" id="Snippet6":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/toboolean2.cs" interactive="try-dotnet-method" id="Snippet6":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/toboolean2.fs" id="Snippet6":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToBoolean/vb/toboolean2.vb" id="Snippet6":::
]]>
@@ -2353,6 +2386,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert.ToBoolean/cpp/toboolean2.cpp" id="Snippet7":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/toboolean2.cs" interactive="try-dotnet-method" id="Snippet7":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/toboolean2.fs" id="Snippet7":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToBoolean/vb/toboolean2.vb" id="Snippet7":::
]]>
@@ -2421,6 +2455,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert.ToBoolean/cpp/toboolean1.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/ToBoolean1.cs" interactive="try-dotnet" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/ToBoolean1.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToBoolean/vb/ToBoolean1.vb" id="Snippet1":::
]]>
@@ -2489,6 +2524,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert.ToBoolean/cpp/toboolean2.cpp" id="Snippet8":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/toboolean2.cs" interactive="try-dotnet-method" id="Snippet8":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/toboolean2.fs" id="Snippet8":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToBoolean/vb/toboolean2.vb" id="Snippet8":::
]]>
@@ -2555,6 +2591,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert.ToBoolean/cpp/toboolean2.cpp" id="Snippet9":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/toboolean2.cs" interactive="try-dotnet-method" id="Snippet9":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/toboolean2.fs" id="Snippet9":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToBoolean/vb/toboolean2.vb" id="Snippet9":::
]]>
@@ -2621,6 +2658,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert.ToBoolean/cpp/toboolean2.cpp" id="Snippet10":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/toboolean2.cs" interactive="try-dotnet-method" id="Snippet10":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/toboolean2.fs" id="Snippet10":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToBoolean/vb/toboolean2.vb" id="Snippet10":::
]]>
@@ -2689,6 +2727,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert.ToXXX_Object_IFP/CPP/objectifp.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/objectifp.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/objectifp.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToXXX_Object_IFP/VB/objectifp.vb" id="Snippet1":::
]]>
@@ -2829,6 +2868,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.convert.tobyte/cpp/tobyte1.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/Byte/Overview/tobyte1.cs" interactive="try-dotnet-method" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Byte/Overview/tobyte1.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tobyte/vb/tobyte1.vb" id="Snippet1":::
]]>
@@ -2937,6 +2977,7 @@
The following example converts an array of values to values.
:::code language="csharp" source="~/snippets/csharp/System/Byte/Overview/tobyte1.cs" interactive="try-dotnet-method" id="Snippet2":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Byte/Overview/tobyte1.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tobyte/vb/tobyte1.vb" id="Snippet2":::
]]>
@@ -3043,6 +3084,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert Snippets/CPP/system.convert snippet.cpp" id="Snippet18":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/system.convert snippet.cs" id="Snippet18":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/system.convert snippet.fs" id="Snippet18":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert Snippets/VB/system.convert snippet.vb" id="Snippet18":::
]]>
@@ -3104,6 +3146,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert Snippets/CPP/system.convert snippet.cpp" id="Snippet2":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/system.convert snippet.cs" id="Snippet2":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/system.convert snippet.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert Snippets/VB/system.convert snippet.vb" id="Snippet2":::
]]>
@@ -3163,6 +3206,7 @@
The following example converts an array of values to values.
:::code language="csharp" source="~/snippets/csharp/System/Byte/Overview/tobyte1.cs" interactive="try-dotnet-method" id="Snippet3":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Byte/Overview/tobyte1.fs" id="Snippet3":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tobyte/vb/tobyte1.vb" id="Snippet3":::
]]>
@@ -3222,6 +3266,7 @@
The following example converts an array of values to values.
:::code language="csharp" source="~/snippets/csharp/System/Byte/Overview/tobyte1.cs" interactive="try-dotnet-method" id="Snippet4":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Byte/Overview/tobyte1.fs" id="Snippet4":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tobyte/vb/tobyte1.vb" id="Snippet4":::
]]>
@@ -3281,6 +3326,7 @@
The following example converts an array of values to values.
:::code language="csharp" source="~/snippets/csharp/System/Byte/Overview/tobyte1.cs" interactive="try-dotnet-method" id="Snippet5":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Byte/Overview/tobyte1.fs" id="Snippet5":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tobyte/vb/tobyte1.vb" id="Snippet5":::
]]>
@@ -3346,6 +3392,7 @@
The following example uses the method to convert an array of objects to values.
:::code language="csharp" source="~/snippets/csharp/System/Byte/Overview/tobyte1.cs" interactive="try-dotnet-method" id="Snippet6":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Byte/Overview/tobyte1.fs" id="Snippet6":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tobyte/vb/tobyte1.vb" id="Snippet6":::
]]>
@@ -3419,6 +3466,7 @@
The following example converts an array of values to values.
:::code language="csharp" source="~/snippets/csharp/System/Byte/Overview/tobyte1.cs" interactive="try-dotnet-method" id="Snippet7":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Byte/Overview/tobyte1.fs" id="Snippet7":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tobyte/vb/tobyte1.vb" id="Snippet7":::
]]>
@@ -3480,6 +3528,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert Snippets/CPP/system.convert snippet.cpp" id="Snippet19":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/system.convert snippet.cs" id="Snippet19":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/system.convert snippet.fs" id="Snippet19":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert Snippets/VB/system.convert snippet.vb" id="Snippet19":::
]]>
@@ -3546,6 +3595,7 @@
The following example defines a string array and attempts to convert each string to a . Note that while a `null` string parses to zero, throws a . Also note that while leading and trailing spaces parse successfully, formatting symbols, such as currency symbols, group separators, or decimal separators, do not.
:::code language="csharp" source="~/snippets/csharp/System/Byte/Overview/ToByte5.cs" interactive="try-dotnet" id="Snippet15":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Byte/Overview/ToByte5.fs" id="Snippet15":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tobyte/vb/tobyte5.vb" id="Snippet15":::
]]>
@@ -3614,6 +3664,7 @@
The following example converts an array of unsigned 16-bit integers to values.
:::code language="csharp" source="~/snippets/csharp/System/Byte/Overview/tobyte1.cs" interactive="try-dotnet-method" id="Snippet8":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Byte/Overview/tobyte1.fs" id="Snippet8":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tobyte/vb/tobyte1.vb" id="Snippet8":::
]]>
@@ -3679,6 +3730,7 @@
The following example converts an array of unsigned integers to values.
:::code language="csharp" source="~/snippets/csharp/System/Byte/Overview/tobyte1.cs" interactive="try-dotnet-method" id="Snippet9":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Byte/Overview/tobyte1.fs" id="Snippet9":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tobyte/vb/tobyte1.vb" id="Snippet9":::
]]>
@@ -3744,6 +3796,7 @@
The following example converts an array of unsigned long integers to values.
:::code language="csharp" source="~/snippets/csharp/System/Byte/Overview/tobyte1.cs" interactive="try-dotnet-method" id="Snippet10":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Byte/Overview/tobyte1.fs" id="Snippet10":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tobyte/vb/tobyte1.vb" id="Snippet10":::
]]>
@@ -3811,11 +3864,13 @@
The following example defines a `ByteString` class that implements the interface. The class stores the string representation of a byte value along with a sign field, so that it is able to represent both signed and unsigned byte values.
:::code language="csharp" source="~/snippets/csharp/System/Byte/Overview/tobyte3.cs" id="Snippet12":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Byte/Overview/tobyte3.fs" id="Snippet12":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tobyte/vb/tobyte3.vb" id="Snippet12":::
The following example instantiates several `ByteString` objects and calls the method to convert them to byte values. It illustrates that the method wraps a call to the method of the object to be converted.
:::code language="csharp" source="~/snippets/csharp/System/Byte/Overview/tobyte3.cs" id="Snippet13":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Byte/Overview/tobyte3.fs" id="Snippet13":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tobyte/vb/tobyte3.vb" id="Snippet13":::
]]>
@@ -3893,6 +3948,7 @@
The following example creates a custom object that defines the positive sign as "pos" and the negative sign as "neg", which it uses in calls to the method. It then calls the method repeatedly to convert each element in a string array to a value.
:::code language="csharp" source="~/snippets/csharp/System/Byte/Overview/tobyte4.cs" interactive="try-dotnet" id="Snippet14":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Byte/Overview/tobyte4.fs" id="Snippet14":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tobyte/vb/tobyte4.vb" id="Snippet14":::
]]>
@@ -3960,11 +4016,13 @@
Because the data type supports unsigned values only, the method assumes that `value` is expressed using unsigned binary representation. In other words, all eight bits are used to represent the numeric value, and a sign bit is absent. As a result, it is possible to write code in which a signed byte value that is out of the range of the data type is converted to a value without the method throwing an exception. The following example converts to its hexadecimal string representation, and then calls the method. Instead of throwing an exception, the method displays the message, "0x80 converts to 128."
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToByte/Conversion.cs" interactive="try-dotnet-method" id="Snippet3":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToByte/Conversion.fs" id="Snippet3":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.BaseConversion/vb/Conversion.vb" id="Snippet3":::
When performing binary operations or numeric conversions, it is always the responsibility of the developer to verify that a method or operator is using the appropriate numeric representation to interpret a particular value. The following example illustrates one technique for ensuring that the method does not inappropriately use unsigned binary representation when it converts a hexadecimal string representation to a value. The example determines whether a value represents a signed or an unsigned integer while it is converting that value to its string representation. When the example converts the value back to a value, it checks whether the original value was a signed integer. If so, and if its high-order bit is set (which indicates that the value is negative and that it uses two's complement instead of unsigned binary representation), the method throws an exception.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToByte/Conversion.cs" interactive="try-dotnet-method" id="Snippet4":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToByte/Conversion.fs" id="Snippet4":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.BaseConversion/vb/Conversion.vb" id="Snippet4":::
@@ -3973,6 +4031,7 @@
The following example alternately attempts to interpret an array of strings as the representation of binary, octal, decimal, and hexadecimal values.
:::code language="csharp" source="~/snippets/csharp/System/Byte/Overview/tobyte2.cs" interactive="try-dotnet" id="Snippet11":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Byte/Overview/tobyte2.fs" id="Snippet11":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tobyte/vb/tobyte2.vb" id="Snippet11":::
]]>
@@ -4101,6 +4160,7 @@
The following example converts an array of unsigned bytes to values.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToChar/tochar1.cs" interactive="try-dotnet-method" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToChar/tochar1.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tochar/vb/tochar1.vb" id="Snippet1":::
]]>
@@ -4246,6 +4306,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert Snippets/CPP/system.convert snippet.cpp" id="Snippet17":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/system.convert snippet.cs" id="Snippet17":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/system.convert snippet.fs" id="Snippet17":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert Snippets/VB/system.convert snippet.vb" id="Snippet17":::
]]>
@@ -4349,6 +4410,7 @@
The following example converts an array of signed 16-bit integers to values.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToChar/tochar1.cs" interactive="try-dotnet-method" id="Snippet2":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToChar/tochar1.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tochar/vb/tochar1.vb" id="Snippet2":::
]]>
@@ -4408,6 +4470,7 @@
The following example converts an array of signed integers to values.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToChar/tochar1.cs" interactive="try-dotnet-method" id="Snippet3":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToChar/tochar1.fs" id="Snippet3":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tochar/vb/tochar1.vb" id="Snippet3":::
]]>
@@ -4468,6 +4531,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert Snippets/CPP/system.convert snippet.cpp" id="Snippet8":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/system.convert snippet.cs" id="Snippet8":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/system.convert snippet.fs" id="Snippet8":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert Snippets/VB/system.convert snippet.vb" id="Snippet8":::
]]>
@@ -4533,6 +4597,7 @@
The following example attempts to convert each element in an object array to a value.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToChar/tochar1.cs" id="Snippet9":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToChar/tochar1.fs" id="Snippet9":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tochar/vb/tochar1.vb" id="Snippet9":::
]]>
@@ -4606,6 +4671,7 @@
The following example converts an array of signed bytes to values.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToChar/tochar1.cs" interactive="try-dotnet-method" id="Snippet4":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToChar/tochar1.fs" id="Snippet4":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tochar/vb/tochar1.vb" id="Snippet4":::
]]>
@@ -4717,6 +4783,7 @@
The following example converts each element in a string array to a value.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToChar/tochar1.cs" interactive="try-dotnet-method" id="Snippet5":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToChar/tochar1.fs" id="Snippet5":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tochar/vb/tochar1.vb" id="Snippet5":::
]]>
@@ -4783,6 +4850,7 @@
The following example converts each element in an array of unsigned 16-bit integers to a value.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToChar/tochar1.cs" interactive="try-dotnet-method" id="Snippet6":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToChar/tochar1.fs" id="Snippet6":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tochar/vb/tochar1.vb" id="Snippet6":::
]]>
@@ -4846,6 +4914,7 @@
The following example converts each element in an array of unsigned integers to a value.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToChar/tochar1.cs" interactive="try-dotnet-method" id="Snippet7":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToChar/tochar1.fs" id="Snippet7":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tochar/vb/tochar1.vb" id="Snippet7":::
]]>
@@ -4911,6 +4980,7 @@
The following example converts each element in an array of unsigned long integers to a value.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToChar/tochar1.cs" interactive="try-dotnet-method" id="Snippet8":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToChar/tochar1.fs" id="Snippet8":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tochar/vb/tochar1.vb" id="Snippet8":::
]]>
@@ -4981,6 +5051,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert.ToXXX_Object_IFP/CPP/objectifp.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/objectifp.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/objectifp.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToXXX_Object_IFP/VB/objectifp.vb" id="Snippet1":::
]]>
@@ -5059,6 +5130,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert.ToNonNum_String/CPP/stringnonnum.cpp" id="Snippet2":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToChar/stringnonnum.cs" id="Snippet2":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToChar/stringnonnum.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToNonNum_String/VB/stringnonnum.vb" id="Snippet2":::
]]>
@@ -5549,6 +5621,7 @@
The following example calls the method with a variety of variables.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToDateTime/ToDateTime1.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToDateTime/ToDateTime1.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToDateTime/vb/ToDateTime1.vb" id="Snippet1":::
]]>
@@ -5722,6 +5795,7 @@
The following example uses the method to convert various string representations of dates and times to values.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToDateTime/ToDateTime2.cs" id="Snippet2":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToDateTime/ToDateTime2.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToDateTime/vb/ToDateTime2.vb" id="Snippet2":::
]]>
@@ -5947,6 +6021,7 @@
The following example defines a custom format provider, `CustomProvider`, whose method outputs a message to the console that it has been invoked, and then returns the object of the culture whose name was passed as a parameter to its class constructor. Each of these `CustomProvider` objects is used to convert the elements in an object array to date and time values. The output indicates that the `CustomProvider` object is used in the conversion only when the type of the `value` parameter is a .
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToDateTime/todatetime4.cs" id="Snippet4":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToDateTime/todatetime4.fs" id="Snippet4":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToDateTime/vb/todatetime4.vb" id="Snippet4":::
]]>
@@ -6025,6 +6100,7 @@
The following example converts string representations of date values with the `ToDateTime` method, using an object.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToDateTime/ToDateTime3.cs" interactive="try-dotnet" id="Snippet3":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToDateTime/ToDateTime3.fs" id="Snippet3":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToDateTime/vb/ToDateTime3.vb" id="Snippet3":::
]]>
@@ -6097,6 +6173,7 @@
The following example illustrates the conversion of to values.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToDecimal/todecimal11.cs" interactive="try-dotnet-method" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToDecimal/todecimal11.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.todecimal2/vb/todecimal1.vb" id="Snippet1":::
]]>
@@ -6156,6 +6233,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert Snippets/CPP/system.convert snippet.cpp" id="Snippet18":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/system.convert snippet.cs" id="Snippet18":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/system.convert snippet.fs" id="Snippet18":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert Snippets/VB/system.convert snippet.vb" id="Snippet18":::
]]>
@@ -6212,6 +6290,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert Snippets/CPP/system.convert snippet.cpp" id="Snippet17":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/system.convert snippet.cs" id="Snippet17":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/system.convert snippet.fs" id="Snippet17":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert Snippets/VB/system.convert snippet.vb" id="Snippet17":::
]]>
@@ -6364,6 +6443,7 @@
The value returned by this method contains a maximum of 15 significant digits. If the `value` parameter contains more than 15 significant digits, it is rounded using rounding to nearest. The following example illustrates how the method uses rounding to nearest to return a value with 15 significant digits.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToDecimal/ToDecimal1.cs" interactive="try-dotnet-method" id="Snippet2":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToDecimal/ToDecimal1.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToDecimal/vb/ToDecimal1.vb" id="Snippet2":::
@@ -6373,6 +6453,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert Snippets/CPP/system.convert snippet.cpp" id="Snippet5":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/system.convert snippet.cs" id="Snippet5":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/system.convert snippet.fs" id="Snippet5":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert Snippets/VB/system.convert snippet.vb" id="Snippet5":::
]]>
@@ -6434,6 +6515,7 @@
The following example converts an array of 16-bit signed integers to values.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToDecimal/todecimal11.cs" interactive="try-dotnet-method" id="Snippet2":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToDecimal/todecimal11.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.todecimal2/vb/todecimal1.vb" id="Snippet2":::
]]>
@@ -6492,6 +6574,7 @@
The following example converts an array of signed integers to values.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToDecimal/todecimal11.cs" interactive="try-dotnet-method" id="Snippet3":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToDecimal/todecimal11.fs" id="Snippet3":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.todecimal2/vb/todecimal1.vb" id="Snippet3":::
]]>
@@ -6551,6 +6634,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert Snippets/CPP/system.convert snippet.cpp" id="Snippet10":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/system.convert snippet.cs" id="Snippet10":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/system.convert snippet.fs" id="Snippet10":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert Snippets/VB/system.convert snippet.vb" id="Snippet10":::
]]>
@@ -6615,6 +6699,7 @@
The following example tries to convert each element in an object array to a value.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToDecimal/todecimal11.cs" interactive="try-dotnet-method" id="Snippet4":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToDecimal/todecimal11.fs" id="Snippet4":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.todecimal2/vb/todecimal1.vb" id="Snippet4":::
]]>
@@ -6689,6 +6774,7 @@
The following example converts each element in an array of signed bytes to a value.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToDecimal/todecimal11.cs" interactive="try-dotnet-method" id="Snippet5":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToDecimal/todecimal11.fs" id="Snippet5":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.todecimal2/vb/todecimal1.vb" id="Snippet5":::
]]>
@@ -6747,6 +6833,7 @@
The value returned by this method contains a maximum of seven significant digits. If the `value` parameter contains more than seven significant digits, it is rounded using rounding to nearest. The following example illustrates how the method uses rounding to nearest to return a value with seven significant digits.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToDecimal/ToDecimal1.cs" interactive="try-dotnet-method" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToDecimal/ToDecimal1.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToDecimal/vb/ToDecimal1.vb" id="Snippet1":::
@@ -6755,6 +6842,7 @@
The following example tries to convert each element in an array of values to a value.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToDecimal/todecimal11.cs" interactive="try-dotnet-method" id="Snippet6":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToDecimal/todecimal11.fs" id="Snippet6":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.todecimal2/vb/todecimal1.vb" id="Snippet6":::
]]>
@@ -6822,6 +6910,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert Snippets/CPP/system.convert snippet.cpp" id="Snippet15":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/system.convert snippet.cs" id="Snippet15":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/system.convert snippet.fs" id="Snippet15":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert Snippets/VB/system.convert snippet.vb" id="Snippet15":::
]]>
@@ -6889,6 +6978,7 @@
The following example converts an array of 16-bit unsigned integers to values.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToDecimal/todecimal11.cs" interactive="try-dotnet-method" id="Snippet7":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToDecimal/todecimal11.fs" id="Snippet7":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.todecimal2/vb/todecimal1.vb" id="Snippet7":::
]]>
@@ -6953,6 +7043,7 @@
The following example converts an array of unsigned integers to values.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToDecimal/todecimal11.cs" interactive="try-dotnet-method" id="Snippet8":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToDecimal/todecimal11.fs" id="Snippet8":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.todecimal2/vb/todecimal1.vb" id="Snippet8":::
]]>
@@ -7017,6 +7108,7 @@
The following example converts an array of unsigned long integers to values.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToDecimal/todecimal11.cs" interactive="try-dotnet-method" id="Snippet9":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToDecimal/todecimal11.fs" id="Snippet9":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.todecimal2/vb/todecimal1.vb" id="Snippet9":::
]]>
@@ -7085,11 +7177,13 @@
The following example defines a `Temperature` class that implements the interface.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToDecimal/todecimal2.cs" id="Snippet10":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToDecimal/todecimal2.fs" id="Snippet10":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.todecimal2/vb/todecimal2.vb" id="Snippet10":::
The following example shows that when a `Temperature` object is passed as a parameter to the method, the implementation of the `Temperature` class is called to perform the conversion.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToDecimal/todecimal2.cs" id="Snippet11":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToDecimal/todecimal2.fs" id="Snippet11":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.todecimal2/vb/todecimal2.vb" id="Snippet11":::
]]>
@@ -7170,6 +7264,7 @@
The following example attempts to convert an array of strings to values by using objects that represent two different cultures.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToDecimal/todecimal3.cs" interactive="try-dotnet" id="Snippet12":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToDecimal/todecimal3.fs" id="Snippet12":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.todecimal2/vb/todecimal3.vb" id="Snippet12":::
]]>
@@ -7244,6 +7339,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert Snippets/CPP/system.convert snippet.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/system.convert snippet.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/system.convert snippet.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert Snippets/VB/system.convert snippet.vb" id="Snippet1":::
]]>
@@ -7302,6 +7398,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert Snippets/CPP/system.convert snippet.cpp" id="Snippet2":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/system.convert snippet.cs" id="Snippet2":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/system.convert snippet.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert Snippets/VB/system.convert snippet.vb" id="Snippet2":::
]]>
@@ -7451,6 +7548,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert Snippets/CPP/system.convert snippet.cpp" id="Snippet5":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/system.convert snippet.cs" id="Snippet5":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/system.convert snippet.fs" id="Snippet5":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert Snippets/VB/system.convert snippet.vb" id="Snippet5":::
]]>
@@ -7557,6 +7655,7 @@
The following example converts each element in an array of 16-bit signed integers to a value.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToDouble/todouble1.cs" interactive="try-dotnet-method" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToDouble/todouble1.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.todouble/vb/todouble1.vb" id="Snippet1":::
]]>
@@ -7615,6 +7714,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert Snippets/CPP/system.convert snippet.cpp" id="Snippet3":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/system.convert snippet.cs" id="Snippet3":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/system.convert snippet.fs" id="Snippet3":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert Snippets/VB/system.convert snippet.vb" id="Snippet3":::
]]>
@@ -7672,6 +7772,7 @@
The following example converts each element in an array of signed long integers to a value.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToDouble/todouble1.cs" interactive="try-dotnet-method" id="Snippet2":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToDouble/todouble1.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.todouble/vb/todouble1.vb" id="Snippet2":::
]]>
@@ -7735,6 +7836,7 @@
The following example attempts to convert each value in an object array to a .
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToDouble/todouble1.cs" interactive="try-dotnet-method" id="Snippet3":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToDouble/todouble1.fs" id="Snippet3":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.todouble/vb/todouble1.vb" id="Snippet3":::
]]>
@@ -7808,6 +7910,7 @@
The following example converts each element in an array of values to a value.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToDouble/todouble1.cs" interactive="try-dotnet-method" id="Snippet4":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToDouble/todouble1.fs" id="Snippet4":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.todouble/vb/todouble1.vb" id="Snippet4":::
]]>
@@ -7866,6 +7969,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert Snippets/CPP/system.convert snippet.cpp" id="Snippet6":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/system.convert snippet.cs" id="Snippet6":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/system.convert snippet.fs" id="Snippet6":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert Snippets/VB/system.convert snippet.vb" id="Snippet6":::
]]>
@@ -7932,6 +8036,7 @@
The following example attempts to convert each element in an array of numeric strings to a . The example's output is from a system whose current culture is en-US.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToDouble/example8.cs" interactive="try-dotnet" id="Snippet8":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToDouble/example8.fs" id="Snippet8":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.todouble/vb/example8.vb" id="Snippet8":::
]]>
@@ -7999,6 +8104,7 @@
The following example converts each element in an array of values to a value.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToDouble/todouble1.cs" interactive="try-dotnet-method" id="Snippet5":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToDouble/todouble1.fs" id="Snippet5":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.todouble/vb/todouble1.vb" id="Snippet5":::
]]>
@@ -8062,6 +8168,7 @@
The following example converts each element in an array of values to a value.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToDouble/todouble1.cs" interactive="try-dotnet-method" id="Snippet6":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToDouble/todouble1.fs" id="Snippet6":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.todouble/vb/todouble1.vb" id="Snippet6":::
]]>
@@ -8125,6 +8232,7 @@
The following example converts each element in an array of values to a value.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToDouble/todouble1.cs" interactive="try-dotnet-method" id="Snippet7":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToDouble/todouble1.fs" id="Snippet7":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.todouble/vb/todouble1.vb" id="Snippet7":::
]]>
@@ -8195,6 +8303,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert.ToXXX_Object_IFP/CPP/objectifp.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/objectifp.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/objectifp.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToXXX_Object_IFP/VB/objectifp.vb" id="Snippet1":::
]]>
@@ -8270,6 +8379,7 @@
The following example converts string representations of values with the `ToDouble` method, using an object.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToDouble/todouble.cs" interactive="try-dotnet" id="Snippet2":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToDouble/todouble.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToReals_String/VB/todouble.vb" id="Snippet2":::
]]>
@@ -8467,6 +8577,7 @@
The following example converts the Boolean values `true` and `false` to values.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt16/toint16_1.cs" interactive="try-dotnet-method" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt16/toint16_1.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint16/vb/toint16_1.vb" id="Snippet1":::
]]>
@@ -8524,6 +8635,7 @@
The following example converts each element in an array of values to a 16-bit signed integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt16/toint16_1.cs" interactive="try-dotnet-method" id="Snippet2":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt16/toint16_1.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint16/vb/toint16_1.vb" id="Snippet2":::
]]>
@@ -8581,6 +8693,7 @@
The following example attempts to convert each element in an array of values to a 16-bit signed integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt16/toint16_1.cs" interactive="try-dotnet-method" id="Snippet3":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt16/toint16_1.fs" id="Snippet3":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint16/vb/toint16_1.vb" id="Snippet3":::
]]>
@@ -8686,6 +8799,7 @@
The following example attempts to convert each element in an array of values to a 16-bit signed integer. The example illustrates that any fractional part of a value is rounded when performing the conversion.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt16/toint16_1.cs" interactive="try-dotnet-method" id="Snippet4":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt16/toint16_1.fs" id="Snippet4":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint16/vb/toint16_1.vb" id="Snippet4":::
]]>
@@ -8747,6 +8861,7 @@
The following example converts each element in an array of values to a 16-bit signed integer. The example illustrates that any fractional part of a value is rounded before performing the conversion.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt16/toint16_1.cs" interactive="try-dotnet-method" id="Snippet5":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt16/toint16_1.fs" id="Snippet5":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint16/vb/toint16_1.vb" id="Snippet5":::
]]>
@@ -8856,6 +8971,7 @@
The following example attempts to convert each element in an array of integers to a 16-bit signed integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt16/toint16_1.cs" interactive="try-dotnet-method" id="Snippet6":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt16/toint16_1.fs" id="Snippet6":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint16/vb/toint16_1.vb" id="Snippet6":::
]]>
@@ -8915,6 +9031,7 @@
The following example attempts to convert each element in an array of long integers to a 16-bit signed integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt16/toint16_1.cs" interactive="try-dotnet-method" id="Snippet7":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt16/toint16_1.fs" id="Snippet7":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint16/vb/toint16_1.vb" id="Snippet7":::
]]>
@@ -8980,6 +9097,7 @@
The following example attempts to convert each element in an object array to a 16-bit signed integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt16/toint16_1.cs" id="Snippet8":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt16/toint16_1.fs" id="Snippet8":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint16/vb/toint16_1.vb" id="Snippet8":::
]]>
@@ -9053,6 +9171,7 @@
The following example converts each element in an array of signed bytes to a 16-bit signed integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt16/toint16_1.cs" interactive="try-dotnet-method" id="Snippet9":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt16/toint16_1.fs" id="Snippet9":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint16/vb/toint16_1.vb" id="Snippet9":::
]]>
@@ -9111,6 +9230,7 @@
The following example attempts to convert each element in an array of values to a 16-bit signed integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt16/toint16_1.cs" interactive="try-dotnet-method" id="Snippet10":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt16/toint16_1.fs" id="Snippet10":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint16/vb/toint16_1.vb" id="Snippet10":::
]]>
@@ -9181,6 +9301,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert.ToSInts_String/CPP/toint16.cpp" id="Snippet3":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt16/toint16.cs" interactive="try-dotnet" id="Snippet3":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt16/toint16.fs" id="Snippet3":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToSInts_String/VB/toint16.vb" id="Snippet3":::
]]>
@@ -9249,6 +9370,7 @@
The following example attempts to convert each element in an array of unsigned 16-bit integers to a 16-bit signed integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt16/toint16_1.cs" interactive="try-dotnet-method" id="Snippet11":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt16/toint16_1.fs" id="Snippet11":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint16/vb/toint16_1.vb" id="Snippet11":::
]]>
@@ -9314,6 +9436,7 @@
The following example attempts to convert each element in an array of unsigned integers to a 16-bit signed integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt16/toint16_1.cs" interactive="try-dotnet-method" id="Snippet12":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt16/toint16_1.fs" id="Snippet12":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint16/vb/toint16_1.vb" id="Snippet12":::
]]>
@@ -9379,6 +9502,7 @@
The following example attempts to convert each element in an array of unsigned long integers to a 16-bit signed integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt16/toint16_1.cs" interactive="try-dotnet-method" id="Snippet13":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt16/toint16_1.fs" id="Snippet13":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint16/vb/toint16_1.vb" id="Snippet13":::
]]>
@@ -9449,6 +9573,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert.ToXXX_Object_IFP/CPP/objectifp.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/objectifp.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/objectifp.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToXXX_Object_IFP/VB/objectifp.vb" id="Snippet1":::
]]>
@@ -9523,6 +9648,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert.ToSInts_String/CPP/toint16.cpp" id="Snippet3":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt16/toint16.cs" interactive="try-dotnet" id="Snippet3":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt16/toint16.fs" id="Snippet3":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToSInts_String/VB/toint16.vb" id="Snippet3":::
]]>
@@ -9590,11 +9716,13 @@
Because the negative sign is not supported for non-base 10 numeric representations, the method assumes that negative numbers use two's complement representation. In other words, the method always interprets the highest-order binary bit of an integer (bit 15) as its sign bit. As a result, it is possible to write code in which a non-base 10 number that is out of the range of the data type is converted to an value without the method throwing an exception. The following example increments by one, converts the resulting number to its hexadecimal string representation, and then calls the method. Instead of throwing an exception, the method displays the message, "0x8000 converts to -32768."
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToByte/Conversion.cs" interactive="try-dotnet-method" id="Snippet5":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToByte/Conversion.fs" id="Snippet5":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.BaseConversion/vb/Conversion.vb" id="Snippet5":::
When performing binary operations or numeric conversions, it is always the responsibility of the developer to verify that a method is using the appropriate numeric representation to interpret a particular value. As the following example illustrates, you can ensure that the method handles overflows appropriately by first retrieving the sign of the numeric value before converting it to its hexadecimal string representation. Throw an exception if the original value was positive but the conversion back to an integer yields a negative value.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToByte/Conversion.cs" interactive="try-dotnet-method" id="Snippet6":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToByte/Conversion.fs" id="Snippet6":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.BaseConversion/vb/Conversion.vb" id="Snippet6":::
@@ -9603,6 +9731,7 @@
The following example attempts to interpret each element in a string array as a hexadecimal string and to convert it to a 16-bit signed integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt16/toint16_2.cs" interactive="try-dotnet" id="Snippet14":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt16/toint16_2.fs" id="Snippet14":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint16/vb/toint16_2.vb" id="Snippet14":::
]]>
@@ -9688,6 +9817,7 @@
The following example converts the values `true` and `false` to integers.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt32/toint32_1.cs" interactive="try-dotnet-method" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt32/toint32_1.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint32/vb/toint32_1.vb" id="Snippet1":::
]]>
@@ -9745,6 +9875,7 @@
The following example converts each element in an array of bytes to an integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt32/toint32_1.cs" interactive="try-dotnet-method" id="Snippet2":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt32/toint32_1.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint32/vb/toint32_1.vb" id="Snippet2":::
]]>
@@ -9807,6 +9938,7 @@
The following example converts each element in an array of values to an integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt32/toint32_1.cs" interactive="try-dotnet-method" id="Snippet3":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt32/toint32_1.fs" id="Snippet3":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint32/vb/toint32_1.vb" id="Snippet3":::
]]>
@@ -9916,6 +10048,7 @@
The following example attempts to convert each element in an array of values to an integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt32/toint32_1.cs" interactive="try-dotnet-method" id="Snippet4":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt32/toint32_1.fs" id="Snippet4":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint32/vb/toint32_1.vb" id="Snippet4":::
]]>
@@ -9977,6 +10110,7 @@
The following example attempts to convert each element in an array of values to an integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt32/toint32_1.cs" interactive="try-dotnet-method" id="Snippet5":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt32/toint32_1.fs" id="Snippet5":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint32/vb/toint32_1.vb" id="Snippet5":::
]]>
@@ -10038,6 +10172,7 @@
The following example converts each element in an array of 16-bit signed integers to an integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt32/toint32_1.cs" interactive="try-dotnet-method" id="Snippet6":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt32/toint32_1.fs" id="Snippet6":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint32/vb/toint32_1.vb" id="Snippet6":::
]]>
@@ -10143,6 +10278,7 @@
The following example attempts to convert each element in an array of long integers to an integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt32/toint32_1.cs" interactive="try-dotnet-method" id="Snippet7":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt32/toint32_1.fs" id="Snippet7":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint32/vb/toint32_1.vb" id="Snippet7":::
]]>
@@ -10208,6 +10344,7 @@
The following example attempts to convert each element in an object array to an integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt32/toint32_1.cs" id="Snippet8":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt32/toint32_1.fs" id="Snippet8":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint32/vb/toint32_1.vb" id="Snippet8":::
]]>
@@ -10281,6 +10418,7 @@
The following example converts each element in an array of signed bytes to an integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt32/toint32_1.cs" interactive="try-dotnet-method" id="Snippet9":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt32/toint32_1.fs" id="Snippet9":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint32/vb/toint32_1.vb" id="Snippet9":::
]]>
@@ -10339,6 +10477,7 @@
The following example attempts to convert each element in an array of values to an integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt32/toint32_1.cs" interactive="try-dotnet-method" id="Snippet10":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt32/toint32_1.fs" id="Snippet10":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint32/vb/toint32_1.vb" id="Snippet10":::
]]>
@@ -10408,6 +10547,7 @@
The following example attempts to convert each element in a numeric string array to an integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt32/toint32_1.cs" interactive="try-dotnet-method" id="Snippet11":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt32/toint32_1.fs" id="Snippet11":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint32/vb/toint32_1.vb" id="Snippet11":::
]]>
@@ -10475,6 +10615,7 @@
The following example converts each element in an array of 16-bit unsigned integers to an integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt32/toint32_1.cs" interactive="try-dotnet-method" id="Snippet12":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt32/toint32_1.fs" id="Snippet12":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint32/vb/toint32_1.vb" id="Snippet12":::
]]>
@@ -10538,6 +10679,7 @@
The following example attempts to convert each element in an array of unsigned integers to a signed integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt32/toint32_1.cs" interactive="try-dotnet-method" id="Snippet13":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt32/toint32_1.fs" id="Snippet13":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint32/vb/toint32_1.vb" id="Snippet13":::
]]>
@@ -10603,6 +10745,7 @@
The following example attempts to convert each element in an array of unsigned long integers to a signed integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt32/toint32_1.cs" interactive="try-dotnet-method" id="Snippet14":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt32/toint32_1.fs" id="Snippet14":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint32/vb/toint32_1.vb" id="Snippet14":::
]]>
@@ -10675,6 +10818,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert.ToXXX_Object_IFP/CPP/objectifp.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/objectifp.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/objectifp.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToXXX_Object_IFP/VB/objectifp.vb" id="Snippet1":::
]]>
@@ -10750,6 +10894,7 @@
The following example defines a custom object that recognizes the string "pos" as the positive sign and the string "neg" as the negative sign. It then attempts to convert each element of a numeric string array to an integer using both this provider and the provider for the invariant culture.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt32/toint32_2.cs" interactive="try-dotnet" id="Snippet15":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt32/toint32_2.fs" id="Snippet15":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint32/vb/toint32_2.vb" id="Snippet15":::
]]>
@@ -10817,12 +10962,14 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert.BaseConversion/cpp/toint_str_int32.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToByte/Conversion.cs" interactive="try-dotnet-method" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToByte/Conversion.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.BaseConversion/vb/Conversion.vb" id="Snippet1":::
When performing binary operations or numeric conversions, it is always the responsibility of the developer to verify that a method is using the appropriate numeric representation to interpret a particular value. As the following example illustrates, you can ensure that the method handles overflows appropriately by first retrieving the sign of the numeric value before converting it to its hexadecimal string representation. Throw an exception if the original value was positive but the conversion back to an integer yields a negative value.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert.BaseConversion/cpp/toint_str_int32.cpp" id="Snippet2":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToByte/Conversion.cs" interactive="try-dotnet-method" id="Snippet2":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToByte/Conversion.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.BaseConversion/vb/Conversion.vb" id="Snippet2":::
]]>
@@ -10908,6 +11055,7 @@
The following example converts the values `true` and `false` to long integers.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt64/toint64_1.cs" interactive="try-dotnet-method" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt64/toint64_1.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint64/vb/toint64_1.vb" id="Snippet1":::
]]>
@@ -10965,6 +11113,7 @@
The following example converts each element in an array of bytes to a long integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt64/toint64_1.cs" interactive="try-dotnet-method" id="Snippet2":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt64/toint64_1.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint64/vb/toint64_1.vb" id="Snippet2":::
]]>
@@ -11022,6 +11171,7 @@
The following example converts each element in a array to a long integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt64/toint64_1.cs" interactive="try-dotnet-method" id="Snippet3":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt64/toint64_1.fs" id="Snippet3":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint64/vb/toint64_1.vb" id="Snippet3":::
]]>
@@ -11125,6 +11275,7 @@
The following example attempts to convert each element in an array of values to a long integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt64/toint64_1.cs" interactive="try-dotnet-method" id="Snippet4":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt64/toint64_1.fs" id="Snippet4":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint64/vb/toint64_1.vb" id="Snippet4":::
]]>
@@ -11192,6 +11343,7 @@
The following example attempts to convert each element in an array of values to a long integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt64/toint64_1.cs" interactive="try-dotnet-method" id="Snippet5":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt64/toint64_1.fs" id="Snippet5":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint64/vb/toint64_1.vb" id="Snippet5":::
]]>
@@ -11253,6 +11405,7 @@
The following example converts each element in an array of 16-bit integers to a long integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt64/toint64_1.cs" interactive="try-dotnet-method" id="Snippet6":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt64/toint64_1.fs" id="Snippet6":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint64/vb/toint64_1.vb" id="Snippet6":::
]]>
@@ -11358,6 +11511,7 @@
The following example converts each element in an array of integers to a long integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt64/toint64_1.cs" interactive="try-dotnet-method" id="Snippet7":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt64/toint64_1.fs" id="Snippet7":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint64/vb/toint64_1.vb" id="Snippet7":::
]]>
@@ -11421,6 +11575,7 @@
The following example attempts to convert each element in an object array to a long integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt64/toint64_1.cs" id="Snippet8":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt64/toint64_1.fs" id="Snippet8":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint64/vb/toint64_1.vb" id="Snippet8":::
]]>
@@ -11494,6 +11649,7 @@
The following example converts each element in a signed byte array to a long integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt64/toint64_1.cs" interactive="try-dotnet-method" id="Snippet9":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt64/toint64_1.fs" id="Snippet9":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint64/vb/toint64_1.vb" id="Snippet9":::
]]>
@@ -11552,6 +11708,7 @@
The following example attempts to convert each element in an array of values to a long integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt64/toint64_1.cs" interactive="try-dotnet-method" id="Snippet10":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt64/toint64_1.fs" id="Snippet10":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint64/vb/toint64_1.vb" id="Snippet10":::
]]>
@@ -11621,6 +11778,7 @@
The following example attempts to convert each element in an array of numeric strings to a long integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt64/toint64_1.cs" interactive="try-dotnet-method" id="Snippet11":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt64/toint64_1.fs" id="Snippet11":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint64/vb/toint64_1.vb" id="Snippet11":::
]]>
@@ -11688,6 +11846,7 @@
The following example converts each element in an array of 16-bit unsigned integers to a long integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt64/toint64_1.cs" interactive="try-dotnet-method" id="Snippet12":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt64/toint64_1.fs" id="Snippet12":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint64/vb/toint64_1.vb" id="Snippet12":::
]]>
@@ -11751,6 +11910,7 @@
The following example converts each element in an array of unsigned integers to a long integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt64/toint64_1.cs" interactive="try-dotnet-method" id="Snippet13":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt64/toint64_1.fs" id="Snippet13":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint64/vb/toint64_1.vb" id="Snippet13":::
]]>
@@ -11814,6 +11974,7 @@
The following example attempts to convert each element in an array of unsigned long integers to a long integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt64/toint64_1.cs" interactive="try-dotnet-method" id="Snippet14":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt64/toint64_1.fs" id="Snippet14":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint64/vb/toint64_1.vb" id="Snippet14":::
]]>
@@ -11886,6 +12047,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert.ToXXX_Object_IFP/CPP/objectifp.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/objectifp.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/objectifp.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToXXX_Object_IFP/VB/objectifp.vb" id="Snippet1":::
]]>
@@ -11965,6 +12127,7 @@
The following example defines a custom object that recognizes the string "pos" as the positive sign and the string "neg" as the negative sign. It then attempts to convert each element of a numeric string array to an integer using both this provider and the provider for the invariant culture.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt64/toint64_3.cs" interactive="try-dotnet" id="Snippet16":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt64/toint64_3.fs" id="Snippet16":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint64/vb/toint64_3.vb" id="Snippet16":::
]]>
@@ -12031,16 +12194,19 @@
Because the negative sign is not supported for non-base 10 numeric representations, the method assumes that negative numbers use two's complement representation. In other words, the method always interprets the highest-order binary bit of a long integer (bit 63) as its sign bit. As a result, it is possible to write code in which a non-base 10 number that is out of the range of the data type is converted to an value without the method throwing an exception. The following example converts to its hexadecimal string representation, and then calls the method. Instead of throwing an exception, the method displays the message, "0xFFFFFFFFFFFFFFFF converts to -1."
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToByte/Conversion.cs" interactive="try-dotnet-method" id="Snippet7":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToByte/Conversion.fs" id="Snippet7":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.BaseConversion/vb/Conversion.vb" id="Snippet7":::
When performing binary operations or numeric conversions, it is always the responsibility of the developer to verify that a method is using the appropriate numeric representation to interpret a particular value. As the following example illustrates, you can ensure that the method handles overflows appropriately by first determining whether a value represents an unsigned or a signed type when converting it to its hexadecimal string representation. Throw an exception if the original value was an unsigned type but the conversion back to an integer yields a value whose sign bit is on.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToByte/Conversion.cs" interactive="try-dotnet-method" id="Snippet8":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToByte/Conversion.fs" id="Snippet8":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.BaseConversion/vb/Conversion.vb" id="Snippet8":::
The following example attempts to interpret each element in a string array as a hexadecimal string and convert it to a long integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt64/toint64_2.cs" interactive="try-dotnet" id="Snippet15":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt64/toint64_2.fs" id="Snippet15":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint64/vb/toint64_2.vb" id="Snippet15":::
]]>
@@ -12132,6 +12298,7 @@
The following example converts the Boolean values `true` and `false` to signed byte values.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToSByte/tosbyte1.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToSByte/tosbyte1.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tosbyte/vb/tosbyte1.vb" id="Snippet1":::
]]>
@@ -12195,6 +12362,7 @@
The following example attempts to convert each element in a byte array to a signed byte.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToSByte/tosbyte1.cs" id="Snippet2":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToSByte/tosbyte1.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tosbyte/vb/tosbyte1.vb" id="Snippet2":::
]]>
@@ -12260,6 +12428,7 @@
The following example attempts to convert each element in an array of values to a signed byte.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToSByte/tosbyte1.cs" id="Snippet3":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToSByte/tosbyte1.fs" id="Snippet3":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tosbyte/vb/tosbyte1.vb" id="Snippet3":::
]]>
@@ -12377,6 +12546,7 @@
The following example attempts to convert each element in an array of values to a signed byte.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToSByte/tosbyte1.cs" id="Snippet4":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToSByte/tosbyte1.fs" id="Snippet4":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tosbyte/vb/tosbyte1.vb" id="Snippet4":::
]]>
@@ -12444,6 +12614,7 @@
The following example attempts to convert each element in an array of values to a signed byte.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToSByte/tosbyte1.cs" id="Snippet5":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToSByte/tosbyte1.fs" id="Snippet5":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tosbyte/vb/tosbyte1.vb" id="Snippet5":::
]]>
@@ -12511,6 +12682,7 @@
The following example attempts to convert each element in an array of signed 16-bit integers to a signed byte.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToSByte/tosbyte1.cs" id="Snippet6":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToSByte/tosbyte1.fs" id="Snippet6":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tosbyte/vb/tosbyte1.vb" id="Snippet6":::
]]>
@@ -12576,6 +12748,7 @@
The following example attempts to convert each element in an array of signed integers to a signed byte.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToSByte/tosbyte1.cs" id="Snippet7":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToSByte/tosbyte1.fs" id="Snippet7":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tosbyte/vb/tosbyte1.vb" id="Snippet7":::
]]>
@@ -12641,6 +12814,7 @@
The following example attempts to convert each element in an array of long integers to a signed byte.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToSByte/tosbyte1.cs" id="Snippet8":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToSByte/tosbyte1.fs" id="Snippet8":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tosbyte/vb/tosbyte1.vb" id="Snippet8":::
]]>
@@ -12712,6 +12886,7 @@
The following example attempts to convert each element in an object array to a signed byte.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToSByte/tosbyte1.cs" id="Snippet9":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToSByte/tosbyte1.fs" id="Snippet9":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tosbyte/vb/tosbyte1.vb" id="Snippet9":::
]]>
@@ -12840,6 +13015,7 @@
The following example attempts to convert each element in an array of values to a signed byte.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToSByte/tosbyte1.cs" id="Snippet9":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToSByte/tosbyte1.fs" id="Snippet9":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tosbyte/vb/tosbyte1.vb" id="Snippet9":::
]]>
@@ -12916,6 +13092,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert.ToSInts_String/CPP/tosbyte.cpp" id="Snippet4":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt16/tosbyte.cs" id="Snippet4":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt16/tosbyte.fs" id="Snippet4":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToSInts_String/VB/tosbyte.vb" id="Snippet4":::
]]>
@@ -12984,6 +13161,7 @@
The following example attempts to convert each element in an array of unsigned 16-bit integers to a signed byte.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToSByte/tosbyte1.cs" id="Snippet11":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToSByte/tosbyte1.fs" id="Snippet11":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tosbyte/vb/tosbyte1.vb" id="Snippet11":::
]]>
@@ -13049,6 +13227,7 @@
The following example attempts to convert each element in an integer array to a signed byte.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToSByte/tosbyte1.cs" id="Snippet12":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToSByte/tosbyte1.fs" id="Snippet12":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tosbyte/vb/tosbyte1.vb" id="Snippet12":::
]]>
@@ -13114,6 +13293,7 @@
The following example attempts to convert each element in an array of long integers to a signed byte.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToSByte/tosbyte1.cs" id="Snippet13":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToSByte/tosbyte1.fs" id="Snippet13":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tosbyte/vb/tosbyte1.vb" id="Snippet13":::
]]>
@@ -13189,11 +13369,13 @@
The following example defines a `ByteString` class that stores both signed and unsigned bytes as hexadecimal strings along with a field that indicates the sign of the byte. The `ByteString` class implements the interface. Its method calls the method to perform the conversion. If it fails, it throws an .
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToSByte/tosbyte2.cs" id="Snippet14":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToSByte/tosbyte2.fs" id="Snippet14":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tosbyte/vb/tosbyte2.vb" id="Snippet14":::
The following example shows how the implementation of the `ByteString` class is called by the method.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToSByte/tosbyte2.cs" id="Snippet15":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToSByte/tosbyte2.fs" id="Snippet15":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tosbyte/vb/tosbyte2.vb" id="Snippet15":::
]]>
@@ -13278,6 +13460,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert.ToSInts_String/CPP/tosbyte.cpp" id="Snippet4":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToInt16/tosbyte.cs" id="Snippet4":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToInt16/tosbyte.fs" id="Snippet4":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToSInts_String/VB/tosbyte.vb" id="Snippet4":::
]]>
@@ -13353,11 +13536,13 @@
Because the negative sign is not supported for non-base 10 numeric representations, the method assumes that negative numbers use two's complement representation. In other words, the method always interprets the high-order bit of a byte (bit 7) as its sign bit. As a result, it is possible to write code in which a non-base 10 number that is out of the range of the data type is converted to an value without the method throwing an exception. The following example converts to its hexadecimal string representation, and then calls the method. Instead of throwing an exception, the method displays the message, "0xff converts to -1."
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToByte/Conversion.cs" id="Snippet9":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToByte/Conversion.fs" id="Snippet9":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.BaseConversion/vb/Conversion.vb" id="Snippet9":::
When performing binary operations or numeric conversions, it is always the responsibility of the developer to verify that a method is using the appropriate numeric representation to interpret a particular value. As the following example illustrates, you can ensure that the method handles overflows appropriately by first determining whether a value represents an unsigned or a signed type when converting it to its hexadecimal string representation. Throw an exception if the original value was an unsigned type but the conversion back to a signed byte yields a value whose sign bit is on.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToByte/Conversion.cs" id="Snippet10":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToByte/Conversion.fs" id="Snippet10":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.BaseConversion/vb/Conversion.vb" id="Snippet10":::
@@ -13366,6 +13551,7 @@
The following example attempts to interpret the elements in a string array as the binary, octal, and hexadecimal representation of numeric values in order to convert them to unsigned bytes.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToSByte/tosbyte3.cs" id="Snippet16":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToSByte/tosbyte3.fs" id="Snippet16":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tosbyte/vb/tosbyte3.vb" id="Snippet16":::
]]>
@@ -13451,6 +13637,7 @@
The following example converts the Boolean values `true` and `false` to values.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToSingle/tosingle1.cs" interactive="try-dotnet-method" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToSingle/tosingle1.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tosingle/vb/tosingle1.vb" id="Snippet1":::
]]>
@@ -13508,6 +13695,7 @@
The following example converts each element in an array of byte values to a value.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToSingle/tosingle1.cs" interactive="try-dotnet-method" id="Snippet2":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToSingle/tosingle1.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tosingle/vb/tosingle1.vb" id="Snippet2":::
]]>
@@ -13658,6 +13846,7 @@
The following example converts each element in an array of values to a value.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToSingle/tosingle1.cs" interactive="try-dotnet-method" id="Snippet3":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToSingle/tosingle1.fs" id="Snippet3":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tosingle/vb/tosingle1.vb" id="Snippet3":::
]]>
@@ -13718,6 +13907,7 @@
The following example converts each element in an array of values to a value.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToSingle/tosingle1.cs" interactive="try-dotnet-method" id="Snippet4":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToSingle/tosingle1.fs" id="Snippet4":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tosingle/vb/tosingle1.vb" id="Snippet4":::
]]>
@@ -13777,6 +13967,7 @@
The following example converts each element in an array of 16-bit integers to a value.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToSingle/tosingle1.cs" interactive="try-dotnet-method" id="Snippet5":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToSingle/tosingle1.fs" id="Snippet5":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tosingle/vb/tosingle1.vb" id="Snippet5":::
]]>
@@ -13834,6 +14025,7 @@
The following example converts each element in an integer array to a value.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToSingle/tosingle1.cs" interactive="try-dotnet-method" id="Snippet6":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToSingle/tosingle1.fs" id="Snippet6":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tosingle/vb/tosingle1.vb" id="Snippet6":::
]]>
@@ -13891,6 +14083,7 @@
The following example converts each element in an array of long integers to a value.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToSingle/tosingle1.cs" interactive="try-dotnet-method" id="Snippet7":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToSingle/tosingle1.fs" id="Snippet7":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tosingle/vb/tosingle1.vb" id="Snippet7":::
]]>
@@ -13954,6 +14147,7 @@
The following example attempts to convert each element in an object array to a value.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToSingle/tosingle1.cs" id="Snippet8":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToSingle/tosingle1.fs" id="Snippet8":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tosingle/vb/tosingle1.vb" id="Snippet8":::
]]>
@@ -14027,6 +14221,7 @@
The following example converts each element in a signed byte array to a value.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToSingle/tosingle1.cs" interactive="try-dotnet-method" id="Snippet9":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToSingle/tosingle1.fs" id="Snippet9":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tosingle/vb/tosingle1.vb" id="Snippet9":::
]]>
@@ -14141,6 +14336,7 @@
The following example attempts to convert each element in an array of numeric strings to a value.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToSingle/tosingle1.cs" interactive="try-dotnet-method" id="Snippet10":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToSingle/tosingle1.fs" id="Snippet10":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tosingle/vb/tosingle1.vb" id="Snippet10":::
]]>
@@ -14208,6 +14404,7 @@
The following example converts each element in an array of unsigned 16-bit integers to a value.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToSingle/tosingle1.cs" interactive="try-dotnet-method" id="Snippet11":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToSingle/tosingle1.fs" id="Snippet11":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tosingle/vb/tosingle1.vb" id="Snippet11":::
]]>
@@ -14271,6 +14468,7 @@
The following example converts each element in an array of unsigned integers to a value.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToSingle/tosingle1.cs" interactive="try-dotnet-method" id="Snippet12":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToSingle/tosingle1.fs" id="Snippet12":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tosingle/vb/tosingle1.vb" id="Snippet12":::
]]>
@@ -14334,6 +14532,7 @@
The following example converts each element in an array of unsigned long integers to a value.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToSingle/tosingle1.cs" interactive="try-dotnet-method" id="Snippet13":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToSingle/tosingle1.fs" id="Snippet13":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tosingle/vb/tosingle1.vb" id="Snippet13":::
]]>
@@ -14403,11 +14602,13 @@
The following example defines a `Temperature` class that implements the interface. Its implementation of the method returns the internal value of a private variable that represents the temperature.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToSingle/tosingle2.cs" id="Snippet14":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToSingle/tosingle2.fs" id="Snippet14":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tosingle/vb/tosingle2.vb" id="Snippet14":::
The following example illustrates how a call to the method, in turn, calls the implementation of the `Temperature` class.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToSingle/tosingle2.cs" id="Snippet15":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToSingle/tosingle2.fs" id="Snippet15":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tosingle/vb/tosingle2.vb" id="Snippet15":::
]]>
@@ -14483,6 +14684,7 @@
The following example uses objects that represent the en-US and fr-FR cultures when it converts the elements in an array of numeric strings to values.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToSingle/tosingle3.cs" interactive="try-dotnet" id="Snippet16":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToSingle/tosingle3.fs" id="Snippet16":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tosingle/vb/tosingle3.vb" id="Snippet16":::
]]>
@@ -14561,6 +14763,7 @@
The following example illustrates the conversion of a to a , using `ToString`. It also illustrates that the string returned by the conversion equals either or .
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToString/ToString_Bool1.cs" interactive="try-dotnet-method" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToString/ToString_Bool1.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToString/vb/ToString_Bool1.vb" id="Snippet1":::
:::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Convert.ToString/fs/ToString_Bool1.fs" id="Snippet1":::
@@ -14624,6 +14827,7 @@
The following example converts each value in a array to a string.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToString/ToString.Byte1.cs" interactive="try-dotnet" id="Snippet3":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToString/ToString.Byte1.fs" id="Snippet3":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToString/vb/ToString.Byte1.vb" id="Snippet3":::
:::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Convert.ToString/fs/ToString_Byte1.fs" id="Snippet3":::
@@ -14688,6 +14892,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert Snippets/CPP/system.convert snippet.cpp" id="Snippet14":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/system.convert snippet.cs" id="Snippet14":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/system.convert snippet.fs" id="Snippet14":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert Snippets/VB/system.convert snippet.vb" id="Snippet14":::
]]>
@@ -14750,6 +14955,7 @@
The following example converts each element in an array of a value to a value.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToString/tostring1.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToString/tostring1.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tostring2/vb/tostring1.vb" id="Snippet1":::
]]>
@@ -14813,6 +15019,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert Snippets/CPP/system.convert snippet.cpp" id="Snippet15":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/system.convert snippet.cs" id="Snippet15":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/system.convert snippet.fs" id="Snippet15":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert Snippets/VB/system.convert snippet.vb" id="Snippet15":::
]]>
@@ -14876,6 +15083,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert Snippets/CPP/system.convert snippet.cpp" id="Snippet7":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToBoolean/system.convert snippet.cs" id="Snippet7":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToBoolean/system.convert snippet.fs" id="Snippet7":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert Snippets/VB/system.convert snippet.vb" id="Snippet7":::
]]>
@@ -14938,6 +15146,7 @@
The following example converts each element in an array of 16-bit integers to its equivalent string representation.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToString/tostring1.cs" interactive="try-dotnet-method" id="Snippet2":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToString/tostring1.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tostring2/vb/tostring1.vb" id="Snippet2":::
]]>
@@ -14998,6 +15207,7 @@
The following example compares the method with the method. It defines a custom object that uses the sting "minus" to represent the negative sign. It converts each element in an integer array to its equivalent string representation using default formatting (the formatting conventions of the current culture) and the custom format provider.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToString/tostring7.cs" interactive="try-dotnet" id="Snippet27":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToString/tostring7.fs" id="Snippet27":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tostring2/vb/tostring7.vb" id="Snippet27":::
]]>
@@ -15060,6 +15270,7 @@
The following example converts each element in a long integer array to its equivalent string representation.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToString/tostring6.cs" interactive="try-dotnet-method" id="Snippet28":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToString/tostring6.fs" id="Snippet28":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tostring2/vb/tostring6.vb" id="Snippet28":::
]]>
@@ -15123,6 +15334,7 @@
The following example converts each element in an object array to its equivalent string representation.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToString/tostring1.cs" id="Snippet3":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToString/tostring1.fs" id="Snippet3":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tostring2/vb/tostring1.vb" id="Snippet3":::
]]>
@@ -15191,6 +15403,7 @@
The following example converts each element in a signed byte array to its equivalent string representation.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToString/tostring1.cs" interactive="try-dotnet-method" id="Snippet4":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToString/tostring1.fs" id="Snippet4":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tostring2/vb/tostring1.vb" id="Snippet4":::
]]>
@@ -15253,6 +15466,7 @@
The following example converts each element in an array of values to its equivalent string representation.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToString/tostring1.cs" interactive="try-dotnet-method" id="Snippet5":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToString/tostring1.fs" id="Snippet5":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tostring2/vb/tostring1.vb" id="Snippet5":::
]]>
@@ -15315,6 +15529,7 @@
The following example passes a string to the method and calls the method to confirm that the method returns the original string. The example also calls the method to ensure that the two strings are not identical because the original string is interned.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToString/tostring_string1.cs" interactive="try-dotnet" id="Snippet2":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToString/tostring_string1.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToString/vb/tostring_string1.vb" id="Snippet2":::
]]>
@@ -15383,6 +15598,7 @@
The following example converts each element in an array of unsigned 16-bit integer values to its equivalent string representation.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToString/tostring1.cs" interactive="try-dotnet-method" id="Snippet6":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToString/tostring1.fs" id="Snippet6":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tostring2/vb/tostring1.vb" id="Snippet6":::
]]>
@@ -15451,6 +15667,7 @@
The following example converts each element in an unsigned integer array to its equivalent string representation.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToString/tostring1.cs" interactive="try-dotnet-method" id="Snippet7":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToString/tostring1.fs" id="Snippet7":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tostring2/vb/tostring1.vb" id="Snippet7":::
]]>
@@ -15519,6 +15736,7 @@
The following example converts each element in an unsigned long integer array to its equivalent string representation.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToString/tostring1.cs" interactive="try-dotnet-method" id="Snippet8":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToString/tostring1.fs" id="Snippet8":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tostring2/vb/tostring1.vb" id="Snippet8":::
]]>
@@ -15585,6 +15803,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert.ToString.IFormatProvider/CPP/nonnumeric.cpp" id="Snippet2":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToString/nonnumeric.cs" id="Snippet2":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToString/nonnumeric.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToString.IFormatProvider/VB/nonnumeric.vb" id="Snippet2":::
]]>
@@ -15650,6 +15869,7 @@
The following example converts each element in an unsigned byte array to its equivalent string representation using the formatting conventions of the en-US and fr-FR cultures. Because the "G" specifier by default outputs only decimal digits in a byte value's string representation, the `provider` parameter does not affect the formatting of the returned string.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToString/tostring3.cs" interactive="try-dotnet-method" id="Snippet16":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToString/tostring3.fs" id="Snippet16":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tostring2/vb/tostring3.vb" id="Snippet16":::
]]>
@@ -15720,6 +15940,7 @@
The following example converts each element in a byte array to its equivalent binary, hexadecimal, decimal, and hexadecimal string representations.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToString/tostring2.cs" interactive="try-dotnet-method" id="Snippet9":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToString/tostring2.fs" id="Snippet9":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tostring2/vb/tostring2.vb" id="Snippet9":::
:::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.convert.tostring2/fs/tostring2.fs" id="Snippet9":::
@@ -15789,6 +16010,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert.ToString.IFormatProvider/CPP/nonnumeric.cpp" id="Snippet2":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToString/nonnumeric.cs" id="Snippet2":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToString/nonnumeric.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToString.IFormatProvider/VB/nonnumeric.vb" id="Snippet2":::
]]>
@@ -15854,6 +16076,7 @@
The following example converts a value to its equivalent string representation in eight different cultures.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToString/tostring3.cs" id="Snippet13":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToString/tostring3.fs" id="Snippet13":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tostring2/vb/tostring3.vb" id="Snippet13":::
]]>
@@ -15919,6 +16142,7 @@
The following example converts each element in an array of values to its equivalent string representation in four different cultures.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToString/tostring3.cs" interactive="try-dotnet-method" id="Snippet14":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToString/tostring3.fs" id="Snippet14":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tostring2/vb/tostring3.vb" id="Snippet14":::
]]>
@@ -15984,6 +16208,7 @@
The following example converts each element in an array of values to its equivalent string representation in four different cultures.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToString/tostring3.cs" interactive="try-dotnet-method" id="Snippet15":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToString/tostring3.fs" id="Snippet15":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tostring2/vb/tostring3.vb" id="Snippet15":::
]]>
@@ -16049,6 +16274,7 @@
The following example defines a custom class that defines its negative sign as the string "~" and its positive sign as the string "!". It then calls the method to convert each element in an array of 16-bit integers to its equivalent string representation. The conversion uses the invariant culture as well as the custom object.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToString/tostring3.cs" interactive="try-dotnet-method" id="Snippet19":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToString/tostring3.fs" id="Snippet19":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tostring2/vb/tostring3.vb" id="Snippet19":::
]]>
@@ -16119,6 +16345,7 @@
The following example converts each element in an array of 16-bit signed integers to its equivalent binary, octal, decimal, and hexadecimal string representations.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToString/tostring2.cs" interactive="try-dotnet-method" id="Snippet10":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToString/tostring2.fs" id="Snippet10":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tostring2/vb/tostring2.vb" id="Snippet10":::
:::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.convert.tostring2/fs/tostring2.fs" id="Snippet10":::
@@ -16187,6 +16414,7 @@
The following example defines a custom class that defines its negative sign as the string "~" and its positive sign as the string "!". It then calls the method to convert each element in an array of integers to its equivalent string representation. The conversion uses the invariant culture as well as the custom object.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToString/tostring3.cs" interactive="try-dotnet-method" id="Snippet20":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToString/tostring3.fs" id="Snippet20":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tostring2/vb/tostring3.vb" id="Snippet20":::
]]>
@@ -16257,6 +16485,7 @@
The following example converts each element in an integer array to its equivalent binary, hexadecimal, decimal, and hexadecimal string representations.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToString/tostring2.cs" interactive="try-dotnet-method" id="Snippet11":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToString/tostring2.fs" id="Snippet11":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tostring2/vb/tostring2.vb" id="Snippet11":::
:::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.convert.tostring2/fs/tostring2.fs" id="Snippet11":::
@@ -16325,6 +16554,7 @@
The following example defines a custom class that defines its negative sign as the string "~" and its positive sign as the string "!". It then calls the method to convert each element in a long integer array to its equivalent string representation. The conversion uses the invariant culture as well as the custom object.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToString/tostring3.cs" interactive="try-dotnet-method" id="Snippet21":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToString/tostring3.fs" id="Snippet21":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tostring2/vb/tostring3.vb" id="Snippet21":::
]]>
@@ -16395,6 +16625,7 @@
The following example converts each element in a long integer array to its equivalent binary, hexadecimal, decimal, and hexadecimal string representations.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToString/tostring2.cs" interactive="try-dotnet-method" id="Snippet12":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToString/tostring2.fs" id="Snippet12":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tostring2/vb/tostring2.vb" id="Snippet12":::
:::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.convert.tostring2/fs/tostring2.fs" id="Snippet12":::
@@ -16465,11 +16696,13 @@
The following example defines a `Temperature` class that overrides the method but does not implement the interface. The example illustrates how calls to the method, in turn, call the `Temperature.ToString` method.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToString/tostring5.cs" interactive="try-dotnet" id="Snippet26":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToString/tostring5.fs" id="Snippet26":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tostring2/vb/tostring5.vb" id="Snippet26":::
The following example defines a `Temperature` class that implements the interface but does not implement the interface. Its implementation represents the `Temperature` value in Celsius, Fahrenheit, or Kelvin, depending on the format string. The example also defines a `TemperatureProvider` class that implements and provides a randomly generated format string that is used by the implementation of the `Temperature` class.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToString/tostring_obj30.cs" interactive="try-dotnet" id="Snippet30":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToString/tostring_obj30.fs" id="Snippet30":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tostring2/vb/tostring_obj30.vb" id="Snippet30":::
]]>
@@ -16541,6 +16774,7 @@
The following example defines a custom class that defines its negative sign as the string "~" and its positive sign as the string "!". It then calls the method to convert each element in signed byte array to its equivalent string representation. The conversion uses the invariant culture as well as the custom object.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToString/tostring3.cs" interactive="try-dotnet-method" id="Snippet17":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToString/tostring3.fs" id="Snippet17":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tostring2/vb/tostring3.vb" id="Snippet17":::
]]>
@@ -16606,6 +16840,7 @@
The following example converts each element in an array of values to its equivalent string representation in four different cultures.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToString/tostring3.cs" id="Snippet18":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToString/tostring3.fs" id="Snippet18":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tostring2/vb/tostring3.vb" id="Snippet18":::
]]>
@@ -16671,6 +16906,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Convert.ToString.IFormatProvider/CPP/nonnumeric.cpp" id="Snippet2":::
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToString/nonnumeric.cs" id="Snippet2":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToString/nonnumeric.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.ToString.IFormatProvider/VB/nonnumeric.vb" id="Snippet2":::
]]>
@@ -16742,6 +16978,7 @@
The following example defines a custom class that defines its negative sign as the string "~" and its positive sign as the string "!". It then calls the method to convert a 16-bit unsigned integer value to its equivalent string representation. The conversion uses both the invariant culture and the custom object. The output indicates that this formatting information is not used, because by default the "G" format specifier does not include a positive sign with positive values.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToString/tostring3.cs" interactive="try-dotnet-method" id="Snippet22":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToString/tostring3.fs" id="Snippet22":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tostring2/vb/tostring3.vb" id="Snippet22":::
]]>
@@ -16813,6 +17050,7 @@
The following example defines a custom class that defines its negative sign as the string "~" and its positive sign as the string "!". It then calls the method to convert an unsigned integer value to its equivalent string representation. The conversion uses both the invariant culture and the custom object. The output indicates that this formatting information is not used, because by default the "G" format specifier does not include a positive sign with positive values.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToString/tostring3.cs" interactive="try-dotnet-method" id="Snippet23":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToString/tostring3.fs" id="Snippet23":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tostring2/vb/tostring3.vb" id="Snippet23":::
]]>
@@ -16884,6 +17122,7 @@
The following example defines a custom class that defines its negative sign as the string "~" and its positive sign as the string "!". It then calls the method to convert an unsigned long integer value to its equivalent string representation. The conversion uses both the invariant culture and the custom object. The output indicates that this formatting information is not used, because by default the "G" format specifier does not include a positive sign with positive values.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToString/tostring3.cs" interactive="try-dotnet-method" id="Snippet24":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToString/tostring3.fs" id="Snippet24":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.tostring2/vb/tostring3.vb" id="Snippet24":::
]]>
@@ -16959,6 +17198,7 @@
The following example converts the Boolean values `true` and `false` to unsigned 16-bit integers.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToUInt16/touint16_1.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToUInt16/touint16_1.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.touint16/vb/touint16_1.vb" id="Snippet1":::
]]>
@@ -17022,6 +17262,7 @@
The following example converts each element in a byte array to an unsigned 16-bit integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToUInt16/touint16_1.cs" id="Snippet2":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToUInt16/touint16_1.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.touint16/vb/touint16_1.vb" id="Snippet2":::
]]>
@@ -17085,6 +17326,7 @@
The following example converts each element in a character array to an unsigned 16-bit integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToUInt16/touint16_1.cs" id="Snippet3":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToUInt16/touint16_1.fs" id="Snippet3":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.touint16/vb/touint16_1.vb" id="Snippet3":::
]]>
@@ -17200,6 +17442,7 @@
The following example converts each element in an array of values to an unsigned 16-bit integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToUInt16/touint16_1.cs" id="Snippet4":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToUInt16/touint16_1.fs" id="Snippet4":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.touint16/vb/touint16_1.vb" id="Snippet4":::
]]>
@@ -17267,6 +17510,7 @@
The following example converts each element in an array of values to an unsigned 16-bit integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToUInt16/touint16_1.cs" id="Snippet5":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToUInt16/touint16_1.fs" id="Snippet5":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.touint16/vb/touint16_1.vb" id="Snippet5":::
]]>
@@ -17334,6 +17578,7 @@
The following example attempts to convert each element in a 16-bit integer array to an unsigned 16-bit integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToUInt16/touint16_1.cs" id="Snippet6":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToUInt16/touint16_1.fs" id="Snippet6":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.touint16/vb/touint16_1.vb" id="Snippet6":::
]]>
@@ -17399,6 +17644,7 @@
The following example converts each element in an integer array to an unsigned 16-bit integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToUInt16/touint16_1.cs" id="Snippet7":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToUInt16/touint16_1.fs" id="Snippet7":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.touint16/vb/touint16_1.vb" id="Snippet7":::
]]>
@@ -17464,6 +17710,7 @@
The following example converts each element in a long integer array to an unsigned 16-bit integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToUInt16/touint16_1.cs" id="Snippet8":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToUInt16/touint16_1.fs" id="Snippet8":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.touint16/vb/touint16_1.vb" id="Snippet8":::
]]>
@@ -17535,6 +17782,7 @@
The following example attempts to convert each element in an object array to an unsigned 16-bit integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToUInt16/touint16_1.cs" id="Snippet9":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToUInt16/touint16_1.fs" id="Snippet9":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.touint16/vb/touint16_1.vb" id="Snippet9":::
]]>
@@ -17608,6 +17856,7 @@
The following example converts each element in a signed byte array to an unsigned 16-bit integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToUInt16/touint16_1.cs" id="Snippet10":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToUInt16/touint16_1.fs" id="Snippet10":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.touint16/vb/touint16_1.vb" id="Snippet10":::
]]>
@@ -17674,6 +17923,7 @@
The following example converts each element in an array of values to an unsigned 16-bit integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToUInt16/touint16_1.cs" id="Snippet11":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToUInt16/touint16_1.fs" id="Snippet11":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.touint16/vb/touint16_1.vb" id="Snippet11":::
]]>
@@ -17749,6 +17999,7 @@
The following example attempts to convert each element in a numeric string array to a 16-bit unsigned integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToUInt16/touint16_1.cs" id="Snippet12":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToUInt16/touint16_1.fs" id="Snippet12":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.touint16/vb/touint16_1.vb" id="Snippet12":::
]]>
@@ -17870,6 +18121,7 @@
The following example attempts to convert each element in an array of unsigned integers to an unsigned 16-bit integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToUInt16/touint16_1.cs" id="Snippet13":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToUInt16/touint16_1.fs" id="Snippet13":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.touint16/vb/touint16_1.vb" id="Snippet13":::
]]>
@@ -17935,6 +18187,7 @@
The following example attempts to convert each element in an array of unsigned long integers to an unsigned 16-bit integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToUInt16/touint16_1.cs" id="Snippet14":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToUInt16/touint16_1.fs" id="Snippet14":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.touint16/vb/touint16_1.vb" id="Snippet14":::
]]>
@@ -18012,11 +18265,13 @@
The following example defines a `HexString` class that implements the interface and that is designed to hold the string representation of both 16-bit signed and 16-bit unsigned values. The class includes a `Sign` property that indicates the sign of its hexadecimal value.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToUInt16/touint16_3.cs" id="Snippet16":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToUInt16/touint16_3.fs" id="Snippet16":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.touint16/vb/touint16_3.vb" id="Snippet16":::
The following example shows that a call to the method that passes a `HexString` object as a parameter, in turn, calls the implementation of the `HexString` class.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToUInt16/touint16_3.cs" id="Snippet17":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToUInt16/touint16_3.fs" id="Snippet17":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.touint16/vb/touint16_3.vb" id="Snippet17":::
]]>
@@ -18102,6 +18357,7 @@
The following example defines a custom object that recognizes the string "pos" as the positive sign and the string "neg" as the negative sign. It then attempts to convert each element of a numeric string array to an integer using both this provider and the provider for the invariant culture.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToUInt16/touint16_4.cs" id="Snippet18":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToUInt16/touint16_4.fs" id="Snippet18":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.touint16/vb/touint16_4.vb" id="Snippet18":::
]]>
@@ -18174,11 +18430,13 @@
Because the data type supports unsigned values only, the method assumes that `value` is expressed using unsigned binary representation. In other words, all 16 bits are used to represent the numeric value, and a sign bit is absent. As a result, it is possible to write code in which a signed integer value that is out of the range of the data type is converted to a value without the method throwing an exception. The following example converts to its hexadecimal string representation, and then calls the method. Instead of throwing an exception, the method displays the message, "0x8000 converts to 32768."
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToByte/Conversion.cs" id="Snippet11":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToByte/Conversion.fs" id="Snippet11":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.BaseConversion/vb/Conversion.vb" id="Snippet11":::
When performing binary operations or numeric conversions, it is always the responsibility of the developer to verify that a method or operator is using the appropriate numeric representation to interpret a particular value. The following example illustrates one technique for ensuring that the method does not inappropriately use binary representation to interpret a value that uses two's complement representation when converting a hexadecimal string to a value. The example determines whether a value represents a signed or an unsigned integer while it is converting that value to its string representation. When the example converts the value to a value, it checks whether the original value was a signed integer. If so, and if its high-order bit is set (which indicates that the original value was negative), the method throws an exception.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToByte/Conversion.cs" id="Snippet12":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToByte/Conversion.fs" id="Snippet12":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Convert.BaseConversion/vb/Conversion.vb" id="Snippet12":::
@@ -18187,6 +18445,7 @@
The following example attempts to interpret each element in an array of numeric strings as a hexadecimal value and to convert it to an unsigned 16-bit integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToUInt16/touint16_2.cs" id="Snippet15":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToUInt16/touint16_2.fs" id="Snippet15":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.touint16/vb/touint16_2.vb" id="Snippet15":::
]]>
@@ -18278,6 +18537,7 @@
The following example converts the Boolean values `true` and `false` to unsigned integers.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToUInt32/touint32_1.cs" interactive="try-dotnet-method" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToUInt32/touint32_1.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.touint32/vb/touint32_1.vb" id="Snippet1":::
]]>
@@ -18341,6 +18601,7 @@
The following example converts each element in a byte array to an unsigned integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToUInt32/touint32_1.cs" interactive="try-dotnet-method" id="Snippet2":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToUInt32/touint32_1.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.touint32/vb/touint32_1.vb" id="Snippet2":::
]]>
@@ -18404,6 +18665,7 @@
The following example converts each element in a character array to an unsigned integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToUInt32/touint32_1.cs" interactive="try-dotnet-method" id="Snippet3":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToUInt32/touint32_1.fs" id="Snippet3":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.touint32/vb/touint32_1.vb" id="Snippet3":::
]]>
@@ -18519,6 +18781,7 @@
The following example attempts to convert each element in an array of values to an unsigned integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToUInt32/touint32_1.cs" interactive="try-dotnet-method" id="Snippet4":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToUInt32/touint32_1.fs" id="Snippet4":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.touint32/vb/touint32_1.vb" id="Snippet4":::
]]>
@@ -18586,6 +18849,7 @@
The following example attempts to convert each element in an array of values to an unsigned integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToUInt32/touint32_1.cs" interactive="try-dotnet-method" id="Snippet5":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToUInt32/touint32_1.fs" id="Snippet5":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.touint32/vb/touint32_1.vb" id="Snippet5":::
]]>
@@ -18653,6 +18917,7 @@
The following example attempts to convert each element in a 16-bit integer array to an unsigned integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToUInt32/touint32_1.cs" interactive="try-dotnet-method" id="Snippet6":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToUInt32/touint32_1.fs" id="Snippet6":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.touint32/vb/touint32_1.vb" id="Snippet6":::
]]>
@@ -18718,6 +18983,7 @@
The following example attempts to convert each element in an integer array to an unsigned integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToUInt32/touint32_1.cs" interactive="try-dotnet-method" id="Snippet7":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToUInt32/touint32_1.fs" id="Snippet7":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.touint32/vb/touint32_1.vb" id="Snippet7":::
]]>
@@ -18783,6 +19049,7 @@
The following example attempts to convert each element in a long integer array to an unsigned integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToUInt32/touint32_1.cs" interactive="try-dotnet-method" id="Snippet8":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToUInt32/touint32_1.fs" id="Snippet8":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.touint32/vb/touint32_1.vb" id="Snippet8":::
]]>
@@ -18854,6 +19121,7 @@
The following example attempts to convert each element in an object array to an unsigned integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToUInt32/touint32_1.cs" id="Snippet9":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToUInt32/touint32_1.fs" id="Snippet9":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.touint32/vb/touint32_1.vb" id="Snippet9":::
]]>
@@ -18927,6 +19195,7 @@
The following example attempts to convert each element in a signed byte array to an unsigned integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToUInt32/touint32_1.cs" interactive="try-dotnet-method" id="Snippet10":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToUInt32/touint32_1.fs" id="Snippet10":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.touint32/vb/touint32_1.vb" id="Snippet10":::
]]>
@@ -18993,6 +19262,7 @@
The following example attempts to convert each element in an array of values to an unsigned integer.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToUInt32/touint32_1.cs" interactive="try-dotnet-method" id="Snippet11":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToUInt32/touint32_1.fs" id="Snippet11":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.touint32/vb/touint32_1.vb" id="Snippet11":::
]]>
@@ -19068,6 +19338,7 @@
The following example interprets the elements in a string array as numeric strings and attempts to convert them to unsigned integers.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToUInt32/touint32_1.cs" interactive="try-dotnet-method" id="Snippet12":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToUInt32/touint32_1.fs" id="Snippet12":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.touint32/vb/touint32_1.vb" id="Snippet12":::
]]>
@@ -19135,6 +19406,7 @@
The following example converts each element in an unsigned 16-bit integer array to an unsigned integer value.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToUInt32/touint32_1.cs" interactive="try-dotnet-method" id="Snippet13":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToUInt32/touint32_1.fs" id="Snippet13":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.touint32/vb/touint32_1.vb" id="Snippet13":::
]]>
@@ -19252,6 +19524,7 @@
The following example attempts to convert each element in an unsigned long integer array to an unsigned integer value.
:::code language="csharp" source="~/snippets/csharp/System/Convert/ToUInt32/touint32_1.cs" interactive="try-dotnet-method" id="Snippet14":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ToUInt32/touint32_1.fs" id="Snippet14":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.touint32/vb/touint32_1.vb" id="Snippet14":::
]]>
@@ -19329,11 +19602,13 @@
The following example defines a `HexString` class that implements the