From 001e2634976825c35635972bc2bbc96faa11bf10 Mon Sep 17 00:00:00 2001 From: albert-du <52804499+albert-du@users.noreply.github.com> Date: Tue, 14 Dec 2021 20:52:29 -0800 Subject: [PATCH] Int64 F# snippets --- .../VS_Snippets_CLR/Int64_Equals/FS/fs.fsproj | 9 + .../Int64_Equals/FS/int64_equals.fs | 15 + .../system.Int64.ToString/fs/ToString.fs | 150 +++++++++ .../system.Int64.ToString/fs/fs.fsproj | 9 + .../system.Int64.TryParse/fs/TryParse1.fs | 37 +++ .../system.Int64.TryParse/fs/TryParse2.fs | 90 +++++ .../system.Int64.TryParse/fs/fs.fsproj | 10 + .../system.convert.toint64/fs/fs.fsproj | 9 + .../system.convert.toint64/fs/toint64_1.fs | 310 ++++++++++++++++++ .../system.int64.equals/fs/equalsoverl.fs | 64 ++++ .../system.int64.equals/fs/fs.fsproj | 9 + .../system.int64.formatting/fs/formatting1.fs | 53 +++ .../system.int64.formatting/fs/fs.fsproj | 9 + .../system.int64.instantiation/fs/fs.fsproj | 9 + .../fs/instantiate1.fs | 89 +++++ .../system.int64.parse/fs/Parse1.fs | 35 ++ .../system.int64.parse/fs/Parse2.fs | 44 +++ .../system.int64.parse/fs/Parse3.fs | 35 ++ .../system.int64.parse/fs/fs.fsproj | 11 + xml/System/Int64.xml | 23 +- 20 files changed, 1018 insertions(+), 2 deletions(-) create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR/Int64_Equals/FS/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR/Int64_Equals/FS/int64_equals.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.Int64.ToString/fs/ToString.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.Int64.ToString/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.Int64.TryParse/fs/TryParse1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.Int64.TryParse/fs/TryParse2.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.Int64.TryParse/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.convert.toint64/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.convert.toint64/fs/toint64_1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.equals/fs/equalsoverl.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.equals/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.formatting/fs/formatting1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.formatting/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.instantiation/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.instantiation/fs/instantiate1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.parse/fs/Parse1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.parse/fs/Parse2.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.parse/fs/Parse3.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.parse/fs/fs.fsproj diff --git a/samples/snippets/fsharp/VS_Snippets_CLR/Int64_Equals/FS/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR/Int64_Equals/FS/fs.fsproj new file mode 100644 index 00000000000..45fa3cb69a5 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR/Int64_Equals/FS/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR/Int64_Equals/FS/int64_equals.fs b/samples/snippets/fsharp/VS_Snippets_CLR/Int64_Equals/FS/int64_equals.fs new file mode 100644 index 00000000000..14f83c5126f --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR/Int64_Equals/FS/int64_equals.fs @@ -0,0 +1,15 @@ +// +let myVariable1 = 80L +let myVariable2 = 80L + +// Get and display the declaring type. +printfn $"\nType of 'myVariable1' is '{myVariable1.GetType()}' and value is: {myVariable1}" +printfn $"\nType of 'myVariable2' is '{myVariable2.GetType()}' and value is: {myVariable2}" + +// Compare 'myVariable1' instance with 'myVariable2' Object. +if myVariable1.Equals myVariable2 then + printfn "\nStructures 'myVariable1' and 'myVariable2' are equal" +else + printfn "\nStructures 'myVariable1' and 'myVariable2' are not equal" + +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.Int64.ToString/fs/ToString.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.Int64.ToString/fs/ToString.fs new file mode 100644 index 00000000000..ce28745cdcd --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.Int64.ToString/fs/ToString.fs @@ -0,0 +1,150 @@ +open System +open System.Globalization + +let callDefaultToString () = + + // + let value = -16325091L + // Display value using default ToString method. + printfn $"{value.ToString()}" // Displays -16325091 + // Display value using some standard format specifiers. + printfn $"""{value.ToString "G"}""" // Displays -16325091 + printfn $"""{value.ToString "C"}""" // Displays ($16,325,091.00) + printfn $"""{value.ToString "D"}""" // Displays -16325091 + printfn $"""{value.ToString "F"}""" // Displays -16325091.00 + printfn $"""{value.ToString "N"}""" // Displays -16,325,091.00 + printfn $"""{value.ToString "N0"}""" // Displays -16,325,091 + printfn $"""{value.ToString "X"}""" // Displays FFFFFFFFFF06E61D + // + +let callToStringWithSpecificCultures () = + // + let value = -16325901L + // Display value using the invariant culture. + printfn $"{value.ToString CultureInfo.InvariantCulture}" + // Display value using the en-GB culture. + printfn $"""{value.ToString(CultureInfo.CreateSpecificCulture "en-GB" )}""" + // Display value using the de-DE culture. + printfn $"""{value.ToString(CultureInfo.CreateSpecificCulture "de-DE" )}""" + // This example displays the following output to the console: + // -16325901 + // -16325901 + // -16325901 + // + + +let callToStringWithSpecificSpecifiers () = + // + let value = -16325L + + // Use standard numeric format specifier. + let specifier = "G" + printfn $"{specifier}: {value.ToString specifier}" + // Displays: G: -16325 + + let specifier = "C" + printfn $"{specifier}: {value.ToString specifier}" + // Displays: C: ($16,325.00) + + let specifier = "D8" + printfn $"{specifier}: {value.ToString specifier}" + // Displays: D8: -00016325 + + let specifier = "E4" + printfn $"{specifier}: {value.ToString specifier}" + // Displays: E4: -1.6325E+004 + + let specifier = "e3" + printfn $"{specifier}: {value.ToString specifier}" + // Displays: e3: -1.633e+004 + + let specifier = "F" + printfn $"{specifier}: {value.ToString specifier}" + // Displays: F: -16325.00 + + let specifier = "N" + printfn $"{specifier}: {value.ToString specifier }" + // Displays: N: -16,325.00 + + let specifier = "P" + printfn $"{specifier}: {(float value / 100000.0).ToString specifier}" + // Displays: P: -16.33 % + + let specifier = "X" + printfn $"{specifier}: {value.ToString(specifier)}" + // Displays: X: FFFFFFFFFFFFC03B + + // Use custom numeric format specifiers. + let specifier = "0,0.000" + printfn $"{specifier}: {value.ToString(specifier)}" + // Displays: 0,0.000: -16,325.000 + + let specifier = "#,#.00#(#,#.00#)" + printfn $"{specifier}: {(value * -1L).ToString specifier}" + // Displays: #,#.00#(#,#.00#): 16,325.00 + + // + +let callToStringWithSpecifiersAndCultures () = + // + // Define cultures whose formatting conventions are to be used. + let cultures = + [| CultureInfo.CreateSpecificCulture "en-US" + CultureInfo.CreateSpecificCulture "fr-FR" + CultureInfo.CreateSpecificCulture "es-ES" |] + + let positiveNumber = 1679L + let negativeNumber = -3045L + let specifiers = [| "G"; "C"; "D8"; "E2"; "F"; "N"; "N0"; "P"; "X8" |] + + for specifier in specifiers do + for culture in cultures do + // Display values with "G" format specifier. + printfn $"{specifier} format using {culture.Name} culture: {positiveNumber.ToString(specifier, culture), 16} {negativeNumber.ToString(specifier, culture), 16}" + printfn "" + + // The example displays the following output to the console: + // G format using en-US culture: 1679 -3045 + // G format using fr-FR culture: 1679 -3045 + // G format using es-ES culture: 1679 -3045 + // + // C format using en-US culture: $1,679.00 ($3,045.00) + // C format using fr-FR culture: 1 679,00 € -3 045,00 € + // C format using es-ES culture: 1.679,00 € -3.045,00 € + // + // D8 format using en-US culture: 00001679 -00003045 + // D8 format using fr-FR culture: 00001679 -00003045 + // D8 format using es-ES culture: 00001679 -00003045 + // + // E2 format using en-US culture: 1.68E+003 -3.05E+003 + // E2 format using fr-FR culture: 1,68E+003 -3,05E+003 + // E2 format using es-ES culture: 1,68E+003 -3,05E+003 + // + // F format using en-US culture: 1679.00 -3045.00 + // F format using fr-FR culture: 1679,00 -3045,00 + // F format using es-ES culture: 1679,00 -3045,00 + // + // N format using en-US culture: 1,679.00 -3,045.00 + // N format using fr-FR culture: 1 679,00 -3 045,00 + // N format using es-ES culture: 1.679,00 -3.045,00 + // + // N0 format using en-US culture: 1,679 -3,045 + // N0 format using fr-FR culture: 1 679 -3 045 + // N0 format using es-ES culture: 1.679 -3.045 + // + // P format using en-US culture: 167,900.00% -304,500.00% + // P format using fr-FR culture: 167 900,00 % -304 500,00 % + // P format using es-ES culture: 167.900,00 % -304.500,00 % + // + // X8 format using en-US culture: 0000068F FFFFFFFFFFFFF41B + // X8 format using fr-FR culture: 0000068F FFFFFFFFFFFFF41B + // X8 format using es-ES culture: 0000068F FFFFFFFFFFFFF41B + // + +callDefaultToString () +printfn "" +callToStringWithSpecificCultures () +printfn "" +callToStringWithSpecificSpecifiers () +printfn "" +callToStringWithSpecifiersAndCultures () \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.Int64.ToString/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.Int64.ToString/fs/fs.fsproj new file mode 100644 index 00000000000..38881a8fd46 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.Int64.ToString/fs/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.Int64.TryParse/fs/TryParse1.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.Int64.TryParse/fs/TryParse1.fs new file mode 100644 index 00000000000..7d8bbf98e4d --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.Int64.TryParse/fs/TryParse1.fs @@ -0,0 +1,37 @@ +module TryParse1 + +// +open System + +let tryToParse (value: string) = + match Int64.TryParse value with + | true, number -> + printfn $"Converted '{value}' to {number}." + | _ -> + let value = + if isNull value then + "" + else + value + printfn $"Attempted conversion of '{value}' failed." + +tryToParse null +tryToParse "160519" +tryToParse "9432.0" +tryToParse "16,667" +tryToParse " -322 " +tryToParse "+4302" +tryToParse "(100);" +tryToParse "01FA" + + +// The example displays the following output to the console: +// Attempted conversion of '' failed. +// Converted '160519' to 160519. +// Attempted conversion of '9432.0' failed. +// Attempted conversion of '16,667' failed. +// Converted ' -322 ' to -322. +// Converted '+4302' to 4302. +// Attempted conversion of '(100);' failed. +// Attempted conversion of '01FA' failed. +// diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.Int64.TryParse/fs/TryParse2.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.Int64.TryParse/fs/TryParse2.fs new file mode 100644 index 00000000000..6f4704bbb8f --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.Int64.TryParse/fs/TryParse2.fs @@ -0,0 +1,90 @@ +module TryParse2 + +// +open System +open System.Globalization + +let callTryParse (stringToConvert: string) styles = + let provider = + // If currency symbol is allowed, use en-US culture. + if int (styles &&& NumberStyles.AllowCurrencySymbol) > 0 then + CultureInfo "en-US" + else + CultureInfo.InvariantCulture + + match Int64.TryParse(stringToConvert, styles, provider) with + | true, number -> + printfn $"Converted '{stringToConvert}' to {number}." + | _ -> + printfn $"Attempted conversion of '{stringToConvert}' failed." + + +[] +let main _ = + let numericString = "106779" + let styles = NumberStyles.Integer + callTryParse numericString styles + + let numericString = "-30677" + let styles = NumberStyles.None + callTryParse numericString styles + + let styles = NumberStyles.AllowLeadingSign + callTryParse numericString styles + + let numericString = "301677-" + callTryParse numericString styles + + let styles = styles ||| NumberStyles.AllowTrailingSign + callTryParse numericString styles + + let numericString = "$10634" + let styles = NumberStyles.Integer + callTryParse numericString styles + + let styles = NumberStyles.Integer ||| NumberStyles.AllowCurrencySymbol + callTryParse numericString styles + + let numericString = "10345.00" + let styles = NumberStyles.Integer ||| NumberStyles.AllowDecimalPoint + callTryParse numericString styles + + let numericString = "10345.72" + let styles = NumberStyles.Integer ||| NumberStyles.AllowDecimalPoint + callTryParse numericString styles + + let numericString = "22,593" + let styles = NumberStyles.Integer ||| NumberStyles.AllowThousands + callTryParse numericString styles + + let numericString = "12E-01" + let styles = NumberStyles.Integer ||| NumberStyles.AllowExponent + callTryParse numericString styles + + let numericString = "12E03" + callTryParse numericString styles + + let numericString = "80c1" + callTryParse numericString NumberStyles.HexNumber + + let numericString = "0x80C1" + callTryParse numericString NumberStyles.HexNumber + + 0 + +// The example displays the following output to the console: +// Converted '106779' to 106779. +// Attempted conversion of '-30677' failed. +// Converted '-30677' to -30677. +// Attempted conversion of '301677-' failed. +// Converted '301677-' to -301677. +// Attempted conversion of '$10634' failed. +// Converted '$10634' to 10634. +// Converted '10345.00' to 10345. +// Attempted conversion of '10345.72' failed. +// Converted '22,593' to 22593. +// Attempted conversion of '12E-01' failed. +// Converted '12E03' to 12000. +// Converted '80c1' to 32961. +// Attempted conversion of '0x80C1' failed. +// diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.Int64.TryParse/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.Int64.TryParse/fs/fs.fsproj new file mode 100644 index 00000000000..682586ee64a --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.Int64.TryParse/fs/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.convert.toint64/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.convert.toint64/fs/fs.fsproj new file mode 100644 index 00000000000..90e94be3215 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.convert.toint64/fs/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.convert.toint64/fs/toint64_1.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.convert.toint64/fs/toint64_1.fs new file mode 100644 index 00000000000..4e9e3f9e195 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.convert.toint64/fs/toint64_1.fs @@ -0,0 +1,310 @@ +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 + let result = Convert.ToInt64 ch + printfn $"Converted the {ch.GetType().Name} value '{ch}' to the {result.GetType().Name} value {result}." + + + // 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.7976931348623157E+308 is outside the range of the Int64 type. + // Converted the Double value '-13800000000' to the Int64 value -13800000000. + // 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.7976931348623157E+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 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 convertInt32 () = + // + let numbers = [| Int32.MinValue; -1; 0; 121; 340; Int32.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 Int32 value -2147483648 to the Int64 value -2147483648. + // 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. + // Converted the Int32 value 2147483647 to the Int64 value 2147483647. + // + +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.4028235E+38 is outside the range of the Int64 type. + // Converted the Single value -1.38E+10 to the Int64 value -13799999488. + // Converted the Single value -1023.299 to the Int64 value -1023. + // Converted the Single value -12.98 to the Int64 value -13. + // Converted the Single value 0 to the Int64 value 0. + // Converted the Single value 9.113E-16 to the Int64 value 0. + // Converted the Single value 103.919 to the Int64 value 104. + // Converted the Single value 17834.191 to the Int64 value 17834. + // 3.4028235E+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 $"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." + + // 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 value in numbers 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." + + // 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 + let result = Convert.ToInt64 number + printfn $"Converted the {number.GetType().Name} value {number:N0} to the {result.GetType().Name} value {result:N0}." + + // 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. + // Converted the UInt32 value 4,294,967,295 to the Int64 value 4,294,967,295. + // + +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 a {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. + // s + +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 () diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.equals/fs/equalsoverl.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.equals/fs/equalsoverl.fs new file mode 100644 index 00000000000..1971b021ef0 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.equals/fs/equalsoverl.fs @@ -0,0 +1,64 @@ +// +let value = 112 + +let testObjectForEquality (obj: obj) = + printfn $"{value} ({value.GetType().Name}) = {obj} ({obj.GetType().Name}): {value.Equals obj}\n" + +let byte1 = 112uy +printfn $"value = byte1: {value.Equals(int byte1),15}" +testObjectForEquality byte1 + +let short1 = 112s +printfn $"value = short1: {value.Equals(int short1),15}" +testObjectForEquality short1 + +let int1 = 112 +printfn $"value = int1: {value.Equals(int int1),17}" +testObjectForEquality int1 + +let sbyte1 = 112y +printfn $"value = sbyte1: {value.Equals(int sbyte1),15}" +testObjectForEquality sbyte1 + +let ushort1 = 112us +printfn $"value = ushort1: {value.Equals(int ushort1),15}" +testObjectForEquality ushort1 + +let uint1 = 112u +printfn $"value = uint1: {value.Equals(int uint1),17}" +testObjectForEquality uint1 + +let dec1 = 112M +printfn $"value = dec1: {value.Equals(int dec1),20}" +testObjectForEquality dec1 + +let dbl1 = 112.0 +printfn $"value = dbl1: {value.Equals(int dbl1),19}" +testObjectForEquality dbl1 + + +// The example displays the following output: +// value = byte1: True +// 112 (Int64) = 112 (Byte): False +// +// value = short1: True +// 112 (Int64) = 112 (Int16): False +// +// value = int1: True +// 112 (Int64) = 112 (Int32): False +// +// value = sbyte1: True +// 112 (Int64) = 112 (SByte): False +// +// value = ushort1: True +// 112 (Int64) = 112 (UInt16): False +// +// value = uint1: True +// 112 (Int64) = 112 (UInt32): False +// +// value = dec1: False +// 112 (Int64) = 112 (Decimal): False +// +// value = dbl1: False +// 112 (Int64) = 112 (Double): False +// diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.equals/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.equals/fs/fs.fsproj new file mode 100644 index 00000000000..f1da800c5f5 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.equals/fs/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.formatting/fs/formatting1.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.formatting/fs/formatting1.fs new file mode 100644 index 00000000000..be5580ca798 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.formatting/fs/formatting1.fs @@ -0,0 +1,53 @@ +open System + +let callToString () = + // + let numbers = [| -1403L; 0L; 169L; 1483104L |] + for number in numbers do + // Display value using default formatting. + printf $"{number.ToString(),-8} --> " + // Display value with 3 digits and leading zeros. + printf $"{number,8:D3}" + // Display value with 1 decimal digit. + printf $"{number,13:N1}" + // Display value as hexadecimal. + printf $"{number,18:X2}" + // Display value with eight hexadecimal digits. + printfn $"{number,18:X8}" + + // The example displays the following output: + // -1403 --> -1403 -1,403.0 FFFFFFFFFFFFFA85 FFFFFFFFFFFFFA85 + // 0 --> 000 0.0 00 00000000 + // 169 --> 169 169.0 A9 000000A9 + // 1483104 --> 1483104 1,483,104.0 16A160 0016A160 + // + +let callConvert () = + // + let numbers = [| -146L; 11043L; 2781913L |] + for number in numbers do + printfn $"{number} (Base 10):" + printfn $" Binary: {Convert.ToString(number, 2)}" + printfn $" Octal: {Convert.ToString(number, 8)}" + printfn $" Hex: {Convert.ToString(number, 16)}\n" + + // The example displays the following output: + // -146 (Base 10): + // Binary: 1111111111111111111111111111111111111111111111111111111101101110 + // Octal: 1777777777777777777556 + // Hex: ffffffffffffff6e + // + // 11043 (Base 10): + // Binary: 10101100100011 + // Octal: 25443 + // Hex: 2b23 + // + // 2781913 (Base 10): + // Binary: 1010100111001011011001 + // Octal: 12471331 + // Hex: 2a72d9 + // + +callToString () +printfn "-----" +callConvert () \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.formatting/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.formatting/fs/fs.fsproj new file mode 100644 index 00000000000..19c8c79ae0b --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.formatting/fs/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.instantiation/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.instantiation/fs/fs.fsproj new file mode 100644 index 00000000000..d4e9c07e95e --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.instantiation/fs/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.instantiation/fs/instantiate1.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.instantiation/fs/instantiate1.fs new file mode 100644 index 00000000000..6d2644a4a7f --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.instantiation/fs/instantiate1.fs @@ -0,0 +1,89 @@ +open System +open System.Globalization +open System.Numerics + +let instantiateByAssignment () = + // + let number1 = -64301728L + let number2 = 255486129307L + // + printfn $"{number1} - {number2}" + + +let instantiateByNarrowingConversion () = + // + let ulNumber = 163245617943825uL + try + let number1 = int64 ulNumber + printfn $"{number1}" + with :? OverflowException -> + printfn $"{ulNumber} is out of range of an Int64." + + let dbl2 = 35901.997 + try + let number2 = int64 dbl2 + printfn $"{number2}" + with :? OverflowException -> + printfn $"{dbl2} is out of range of an Int64." + + let bigNumber = BigInteger 1.63201978555e30 + try + let number3 = int64 bigNumber + printfn $"{number3}" + with :? OverflowException -> + printfn $"{bigNumber} is out of range of an Int64." + + // The example displays the following output: + // 163245617943825 + // 35902 + // 1,632,019,785,549,999,969,612,091,883,520 is out of range of an Int64. + // + +let parse () = + // + let string1 = "244681903147" + try + let number1 = Int64.Parse string1 + printfn $"{number1}" + with + | :? OverflowException -> + printfn $"'{string1}' is out of range of a 64-bit integer." + | :? FormatException -> + printfn $"The format of '{string1}' is invalid." + + let string2 = "F9A3CFF0A" + try + let number2 = Int64.Parse(string2, NumberStyles.HexNumber) + printfn $"{number2}" + + with + | :? OverflowException -> + printfn $"'{string2}' is out of range of a 64-bit integer." + | :? FormatException -> + printfn $"The format of '{string2}' is invalid." + + // The example displays the following output: + // 244681903147 + // 67012198154 + // + +let instantiateByWideningConversion () = + // + let value1 = 124y + let value2 = 1618s + let value3 = Int32.MaxValue + + let number1 = int64 value1 + let number2 = int64 value2 + let number3: int64 = value3 + // + () + + +instantiateByAssignment () +printfn "----" +instantiateByNarrowingConversion () +printfn "----" +parse () +printfn "----" +instantiateByWideningConversion () \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.parse/fs/Parse1.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.parse/fs/Parse1.fs new file mode 100644 index 00000000000..b7806a99a4a --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.parse/fs/Parse1.fs @@ -0,0 +1,35 @@ +module Parse1 + +// +open System + +let convert value = + try + let number = Int64.Parse value + printfn $"Converted '{value}' to {number}." + with + | :? FormatException -> + printfn $"Unable to convert '{value}'." + | :? OverflowException -> + printfn $"'{value}' is out of range." + +convert " 179042 " +convert " -2041326 " +convert " +8091522 " +convert " 1064.0 " +convert " 178.3" +convert String.Empty + +decimal Int64.MaxValue + 1M +|> string +|> convert + +// This example displays the following output to the console: +// Converted ' 179042 ' to 179042. +// Converted ' -2041326 ' to -2041326. +// Converted ' +8091522 ' to 8091522. +// Unable to convert ' 1064.0 '. +// Unable to convert ' 178.3'. +// Unable to convert ''. +// '92233720368547758071' is out of range. +// diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.parse/fs/Parse2.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.parse/fs/Parse2.fs new file mode 100644 index 00000000000..0d15462becf --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.parse/fs/Parse2.fs @@ -0,0 +1,44 @@ +module Parse2 + +// +open System +open System.Globalization + +let convert value (style: NumberStyles) = + try + let number = Int64.Parse(value, style) + printfn $"converted '{value}' to {number}." + with + | :? FormatException -> + printfn $"Unable to convert '{value}'." + | :? OverflowException -> + printfn $"'{value}' is out of range of the Int64 type." + +convert "104.0" NumberStyles.AllowDecimalPoint +convert "104.9" NumberStyles.AllowDecimalPoint +convert " 106034" NumberStyles.None +convert " $17,198,064.42" (NumberStyles.AllowCurrencySymbol ||| NumberStyles.Number) +convert " $17,198,064.00" (NumberStyles.AllowCurrencySymbol ||| NumberStyles.Number) +convert "103E06" NumberStyles.AllowExponent +convert "1200E-02" NumberStyles.AllowExponent +convert "1200E-03" NumberStyles.AllowExponent +convert "-1,345,791" NumberStyles.AllowThousands +convert "(1,345,791)" (NumberStyles.AllowThousands ||| NumberStyles.AllowParentheses) +convert "FFCA00A0" NumberStyles.HexNumber +convert "0xFFCA00A0" NumberStyles.HexNumber + + +// The example displays the following output to the console: +// converted '104.0' to 104. +// '104.9' is out of range of the Int64 type. +// Unable to convert ' 106034'. +// ' $17,198,064.42' is out of range of the Int64 type. +// converted ' $17,198,064.00' to 17198064. +// converted '103E06' to 103000000. +// converted '1200E-02' to 12. +// '1200E-03' is out of range of the Int64 type. +// Unable to convert '-1,345,791'. +// converted '(1,345,791)' to -1345791. +// converted 'FFCA00A0' to 4291428512. +// Unable to convert '0xFFCA00A0'. +// diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.parse/fs/Parse3.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.parse/fs/Parse3.fs new file mode 100644 index 00000000000..80047f90ecf --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.parse/fs/Parse3.fs @@ -0,0 +1,35 @@ +module Parse3 + +// +open System +open System.Globalization + +let convert (value: string) style provider = + try + let number = Int64.Parse(value, style, provider) + printfn $"Converted '{value}' to {number}." + with + | :? FormatException -> + printfn $"Unable to convert '{value}'." + | :? OverflowException -> + printfn $"'{value}' is out of range of the Int64 type." + +convert "12,000" (NumberStyles.Float ||| NumberStyles.AllowThousands) (CultureInfo "en-GB") +convert "12,000" (NumberStyles.Float ||| NumberStyles.AllowThousands) (CultureInfo "fr-FR") +convert "12,000" NumberStyles.Float (CultureInfo "en-US") +convert "12 425,00" (NumberStyles.Float ||| NumberStyles.AllowThousands) (CultureInfo "sv-SE") +convert "12,425.00" (NumberStyles.Float ||| NumberStyles.AllowThousands) NumberFormatInfo.InvariantInfo +convert "631,900" (NumberStyles.Integer ||| NumberStyles.AllowDecimalPoint) (CultureInfo "fr-FR") +convert "631,900" (NumberStyles.Integer ||| NumberStyles.AllowDecimalPoint) (CultureInfo "en-US") +convert "631,900" (NumberStyles.Integer ||| NumberStyles.AllowThousands) (CultureInfo "en-US") + +// This example displays the following output to the console: +// Converted '12,000' to 12000. +// Converted '12,000' to 12. +// Unable to convert '12,000'. +// Converted '12 425,00' to 12425. +// Converted '12,425.00' to 12425. +// '631,900' is out of range of the Int64 type. +// Unable to convert '631,900'. +// Converted '631,900' to 631900. +// diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.parse/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.parse/fs/fs.fsproj new file mode 100644 index 00000000000..45ea0af5936 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.parse/fs/fs.fsproj @@ -0,0 +1,11 @@ + + + Exe + net6.0 + + + + + + + \ No newline at end of file diff --git a/xml/System/Int64.xml b/xml/System/Int64.xml index f7acd1440db..853a689ca6b 100644 --- a/xml/System/Int64.xml +++ b/xml/System/Int64.xml @@ -101,26 +101,31 @@ - You can declare an variable and assign it a literal integer value that is within the range of the data type. The following example declares two variables and assigns them values in this way. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.int64.instantiation/cs/instantiate1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.instantiation/fs/instantiate1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.int64.instantiation/vb/instantiate1.vb" id="Snippet1"::: -- You can assign the value of an integral type whose range is a subset of the type. This is a widening conversion that does not require a cast operator in C# or a conversion method in Visual Basic. +- You can assign the value of an integral type whose range is a subset of the type. This is a widening conversion that does not require a cast operator in C# or a conversion method in Visual Basic. In F#, only the type can be widened automatically. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.int64.instantiation/cs/instantiate1.cs" id="Snippet4"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.instantiation/fs/instantiate1.fs" id="Snippet4"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.int64.instantiation/vb/instantiate1.vb" id="Snippet4"::: -- You can assign the value of a numeric type whose range exceeds that of the type. This is a narrowing conversion, so it requires a cast operator in C# and a conversion method in Visual Basic if `Option Strict` is on. If the numeric value is a , , or value that includes a fractional component, the handling of its fractional part depends on the compiler performing the conversion. The following example performs narrowing conversions to assign several numeric values to variables. +- You can assign the value of a numeric type whose range exceeds that of the type. This is a narrowing conversion, so it requires a cast operator in C# or F# and a conversion method in Visual Basic if `Option Strict` is on. If the numeric value is a , , or value that includes a fractional component, the handling of its fractional part depends on the compiler performing the conversion. The following example performs narrowing conversions to assign several numeric values to variables. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.int64.instantiation/cs/instantiate1.cs" id="Snippet2"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.instantiation/fs/instantiate1.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.int64.instantiation/vb/instantiate1.vb" id="Snippet2"::: - You can call a method of the class to convert any supported type to an value. This is possible because supports the interface. The following example illustrates the conversion of an array of values to values. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.convert.toint64/cs/toint64_1.cs" interactive="try-dotnet-method" id="Snippet4"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.convert.toint64/fs/toint64_1.fs" id="Snippet4"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint64/vb/toint64_1.vb" id="Snippet4"::: - You can call the or method to convert the string representation of an value to an . The string can contain either decimal or hexadecimal digits. The following example illustrates the parse operation by using both a decimal and a hexadecimal string. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.int64.instantiation/cs/instantiate1.cs" interactive="try-dotnet-method" id="Snippet3"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.instantiation/fs/instantiate1.fs" id="Snippet3"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.int64.instantiation/vb/instantiate1.vb" id="Snippet3"::: ## Performing Operations on Int64 Values @@ -136,11 +141,13 @@ To format an value as an integral string with no leading zeros, you can call the parameterless method. By using the "D" format specifier, you can also include a specified number of leading zeros in the string representation. By using the "N" format specifier, you can include group separators and specify the number of decimal digits to appear in the string representation of the number. By using the "X" format specifier, you can represent an value as a hexadecimal string. The following example formats the elements in an array of values in these four ways. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.int64.formatting/cs/formatting1.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.formatting/fs/formatting1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.int64.formatting/vb/formatting1.vb" id="Snippet1"::: You can also format an value as a binary, octal, decimal, or hexadecimal string by calling the method and supplying the base as the method's second parameter. The following example calls this method to display the binary, octal, and hexadecimal representations of an array of integer values. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.int64.formatting/cs/formatting1.cs" interactive="try-dotnet-method" id="Snippet2"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.formatting/fs/formatting1.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.int64.formatting/vb/formatting1.vb" id="Snippet2"::: ## Working with Non-Decimal 32-Bit Integer Values @@ -402,6 +409,7 @@ Compiler overload resolution may account for an apparent difference in the behavior of the two method overloads. If an implicit conversion between the argument and an is defined and the argument is not typed as an , compilers perform an implicit conversion and call the method. Otherwise, they call the method, which always returns if its argument is not an value. The following example illustrates the difference in behavior between the two method overloads. In the case of the , , , , , and values, the first comparison returns because the compiler automatically performs a widening conversion and calls the method, whereas the second comparison returns because the compiler calls the method. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.int64.equals/cs/equalsoverl.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.equals/fs/equalsoverl.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.int64.equals/vb/equalsoverl.vb" id="Snippet1"::: @@ -458,6 +466,7 @@ :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR/Int64_Equals/CPP/int64_equals.cpp" id="Snippet1"::: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/Int64_Equals/CS/int64_equals.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR/Int64_Equals/FS/int64_equals.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/Int64_Equals/VB/int64_equals.vb" id="Snippet1"::: ]]> @@ -466,6 +475,7 @@ Compiler overload resolution may account for an apparent difference in the behavior of the two method overloads. If an implicit conversion between the argument and an is defined and the argument is not typed as an , compilers perform an implicit conversion and call the method. Otherwise, they call the method, which always returns if its argument is not an value. The following example illustrates the difference in behavior between the two method overloads. In the case of the , , , , , and values, the first comparison returns because the compiler automatically performs a widening conversion and calls the method, whereas the second comparison returns because the compiler calls the method. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.int64.equals/cs/equalsoverl.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.equals/fs/equalsoverl.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.int64.equals/vb/equalsoverl.vb" id="Snippet1"::: @@ -735,6 +745,7 @@ The following example demonstrates how to convert a string value into a 64-bit signed integer value using the method. It then displays the resulting long integer value. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.int64.parse/cs/Parse1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.parse/fs/Parse1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.int64.parse/vb/Parse1.vb" id="Snippet1"::: ]]> @@ -850,6 +861,7 @@ The following example uses the method to parse the string representations of several values. The current culture for the example is en-US. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.int64.parse/cs/Parse2.cs" interactive="try-dotnet" id="Snippet2"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.parse/fs/Parse2.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.int64.parse/vb/Parse2.vb" id="Snippet2"::: ]]> @@ -1105,6 +1117,7 @@ The following example uses a variety of `style` and `provider` parameters to parse the string representations of values. It also illustrates some of the different ways the same string can be interpreted depending on the culture whose formatting information is used for the parsing operation. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.int64.parse/cs/Parse3.cs" interactive="try-dotnet" id="Snippet3"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.parse/fs/Parse3.fs" id="Snippet3"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.int64.parse/vb/Parse3.vb" id="Snippet3"::: ]]> @@ -2118,6 +2131,7 @@ This member is an explicit interface member implementation. It can be used only The following example displays an value using the default method. It also displays the string representations of the value that results from using a number of standard format specifiers. The examples are displayed using the formatting conventions of the en-US culture. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Int64.ToString/cs/ToString.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.Int64.ToString/fs/ToString.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Int64.ToString/vb/ToString.vb" id="Snippet1"::: ]]> @@ -2215,6 +2229,7 @@ This member is an explicit interface member implementation. It can be used only The following example displays the string representation of an value using objects that represent several different cultures. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Int64.ToString/cs/ToString.cs" interactive="try-dotnet-method" id="Snippet2"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.Int64.ToString/fs/ToString.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Int64.ToString/vb/ToString.vb" id="Snippet2"::: ]]> @@ -2301,6 +2316,7 @@ This member is an explicit interface member implementation. It can be used only The following example displays an value using each of the supported standard numeric format specifiers together with two custom numeric format strings. In converting the numeric values to strings, the example uses the formatting conventions of the en-US culture. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Int64.ToString/cs/ToString.cs" id="Snippet3"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.Int64.ToString/fs/ToString.fs" id="Snippet3"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Int64.ToString/vb/ToString.vb" id="Snippet3"::: ]]> @@ -2405,6 +2421,7 @@ This member is an explicit interface member implementation. It can be used only The following example displays a positive and a negative value using each of the supported standard numeric format specifiers for three different cultures. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Int64.ToString/cs/ToString.cs" interactive="try-dotnet-method" id="Snippet4"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.Int64.ToString/fs/ToString.fs" id="Snippet4"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Int64.ToString/vb/ToString.vb" id="Snippet4"::: ]]> @@ -2602,6 +2619,7 @@ This member is an explicit interface member implementation. It can be used only The following example calls the method with a number of different string values. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Int64.TryParse/cs/TryParse1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.Int64.TryParse/fs/TryParse1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Int64.TryParse/vb/TryParse1.vb" id="Snippet1"::: Some of the strings that the method is unable to convert in this example are: @@ -2780,6 +2798,7 @@ This member is an explicit interface member implementation. It can be used only The following example calls the method with a number of different string and values. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Int64.TryParse/cs/TryParse2.cs" interactive="try-dotnet" id="Snippet2"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.Int64.TryParse/fs/TryParse2.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Int64.TryParse/vb/TryParse2.vb" id="Snippet2"::: ]]>