diff --git a/snippets/fsharp/System/UInt64/CompareTo/fs.fsproj b/snippets/fsharp/System/UInt64/CompareTo/fs.fsproj new file mode 100644 index 00000000000..f0a89cd967d --- /dev/null +++ b/snippets/fsharp/System/UInt64/CompareTo/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/UInt64/CompareTo/source.fs b/snippets/fsharp/System/UInt64/CompareTo/source.fs new file mode 100644 index 00000000000..f4e90b39404 --- /dev/null +++ b/snippets/fsharp/System/UInt64/CompareTo/source.fs @@ -0,0 +1,22 @@ +// +open System + +type Temperature() = + // The value holder + let mutable m_value = 0uL + + interface IComparable with + /// IComparable.CompareTo implementation. + member _.CompareTo(obj) = + match obj with + | :? Temperature as temp -> + m_value.CompareTo temp.Value + | _ -> + invalidArg "obj" "object is not a Temperature" + + member _.Value + with get () = + m_value + and set (v) = + m_value <- v +// \ No newline at end of file diff --git a/snippets/fsharp/System/UInt64/Equals/equals1.fs b/snippets/fsharp/System/UInt64/Equals/equals1.fs new file mode 100644 index 00000000000..65af871115e --- /dev/null +++ b/snippets/fsharp/System/UInt64/Equals/equals1.fs @@ -0,0 +1,29 @@ +module equals1 + +// +let values: obj[] = + [| 10s; 20s; 10; 20 + 10L; 20L; 10.; 20.; 10us + 20us; 10u; 20u + 10uL; 20uL |] +let baseValue = 20uL +let baseType = baseValue.GetType().Name + +for value in values do + printfn $"{baseValue} ({baseType}) = {value} ({value.GetType().Name}): {value.GetType().Name}" +// The example displays the following output: +// 20 (UInt64) = 10 (Int16): False +// 20 (UInt64) = 20 (Int16): False +// 20 (UInt64) = 10 (Int32): False +// 20 (UInt64) = 20 (Int32): False +// 20 (UInt64) = 10 (Int64): False +// 20 (UInt64) = 20 (Int64): False +// 20 (UInt64) = 10 (Double): False +// 20 (UInt64) = 20 (Double): False +// 20 (UInt64) = 10 (UInt16): False +// 20 (UInt64) = 20 (UInt16): False +// 20 (UInt64) = 10 (UInt32): False +// 20 (UInt64) = 20 (UInt32): False +// 20 (UInt64) = 10 (UInt64): False +// 20 (UInt64) = 20 (UInt64): True +// \ No newline at end of file diff --git a/snippets/fsharp/System/UInt64/Equals/equalsoverl.fs b/snippets/fsharp/System/UInt64/Equals/equalsoverl.fs new file mode 100644 index 00000000000..ccf9b3d8f9a --- /dev/null +++ b/snippets/fsharp/System/UInt64/Equals/equalsoverl.fs @@ -0,0 +1,65 @@ +module equalsoverl + +// +let value = 112uL + +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 byte1,16}" +testObjectForEquality byte1 + +let short1 = 112s +printfn $"value = short1: {value.Equals short1,17}" +testObjectForEquality short1 + +let int1 = 112 +printfn $"value = int1: {value.Equals int1,19}" +testObjectForEquality int1 + +let sbyte1 = 112y +printfn $"value = sbyte1: {value.Equals sbyte1,17}" +testObjectForEquality sbyte1 + +let ushort1 = 112us +printfn $"value = ushort1: {value.Equals ushort1,16}" +testObjectForEquality ushort1 + +let uint1 = 112u +printfn $"value = uint1: {value.Equals uint1,18}" +testObjectForEquality uint1 + +let dec1 = 112m +printfn $"value = dec1: {value.Equals dec1,21}" +testObjectForEquality dec1 + +let dbl1 = 112. +printfn $"value = dbl1: {value.Equals dbl1,20}" +testObjectForEquality dbl1 + +// The example displays the following output: +// value = byte1: True +// 112 (UInt64) = 112 (Byte): False +// +// value = short1: False +// 112 (UInt64) = 112 (Int16): False +// +// value = int1: False +// 112 (UInt64) = 112 (Int32): False +// +// value = sbyte1: False +// 112 (UInt64) = 112 (SByte): False +// +// value = ushort1: True +// 112 (UInt64) = 112 (UInt16): False +// +// value = uint1: True +// 112 (UInt64) = 112 (UInt32): False +// +// value = dec1: False +// 112 (UInt64) = 112 (Decimal): False +// +// value = dbl1: False +// 112 (UInt64) = 112 (Double): False +// \ No newline at end of file diff --git a/snippets/fsharp/System/UInt64/Equals/fs.fsproj b/snippets/fsharp/System/UInt64/Equals/fs.fsproj new file mode 100644 index 00000000000..91ccd66a092 --- /dev/null +++ b/snippets/fsharp/System/UInt64/Equals/fs.fsproj @@ -0,0 +1,12 @@ + + + Exe + net6.0 + + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/UInt64/Equals/uint64_equals.fs b/snippets/fsharp/System/UInt64/Equals/uint64_equals.fs new file mode 100644 index 00000000000..b9e04408d90 --- /dev/null +++ b/snippets/fsharp/System/UInt64/Equals/uint64_equals.fs @@ -0,0 +1,17 @@ +module uint64_equals + +// +let value1 = 50uL +let value2 = 50uL + +// Display the values. +printfn $"value1: Type: {value1.GetType().Name} Value: {value1}" +printfn $"value2: Type: {value2.GetType().Name} Value: {value2}" + +// Compare the two values. +printfn $"value1 and value2 are equal: {value1.Equals value2}" +// The example displays the following output: +// value1: Type: UInt64 Value: 50 +// value2: Type: UInt64 Value: 50 +// value1 and value2 are equal: True +// \ No newline at end of file diff --git a/snippets/fsharp/System/UInt64/MaxValue/MaxValue1.fs b/snippets/fsharp/System/UInt64/MaxValue/MaxValue1.fs new file mode 100644 index 00000000000..e239c70dd0f --- /dev/null +++ b/snippets/fsharp/System/UInt64/MaxValue/MaxValue1.fs @@ -0,0 +1,20 @@ +// +open System + +let decimalValue = -1.5 + +// Discard fractional portion of Double value +let decimalInteger = floor decimalValue + +if decimalInteger <= float UInt64.MaxValue && decimalInteger >= float UInt64.MinValue then + let integerValue = uint64 decimalValue + printfn $"Converted {decimalValue} to {integerValue}." +else + let rangeLimit, relationship = + if decimalInteger > float UInt64.MaxValue then + UInt64.MaxValue, "greater" + else + UInt64.MinValue, "less" + + printfn $"Conversion failure: {decimalInteger} is {relationship} than {rangeLimit}." +// \ No newline at end of file diff --git a/snippets/fsharp/System/UInt64/MaxValue/fs.fsproj b/snippets/fsharp/System/UInt64/MaxValue/fs.fsproj new file mode 100644 index 00000000000..435cf5da6ef --- /dev/null +++ b/snippets/fsharp/System/UInt64/MaxValue/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/UInt64/Parse/fs.fsproj b/snippets/fsharp/System/UInt64/Parse/fs.fsproj new file mode 100644 index 00000000000..e4005924808 --- /dev/null +++ b/snippets/fsharp/System/UInt64/Parse/fs.fsproj @@ -0,0 +1,12 @@ + + + Exe + net6.0 + + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/UInt64/Parse/parse1.fs b/snippets/fsharp/System/UInt64/Parse/parse1.fs new file mode 100644 index 00000000000..a2a992726cb --- /dev/null +++ b/snippets/fsharp/System/UInt64/Parse/parse1.fs @@ -0,0 +1,31 @@ +module parse1 + +open System + +// +let values = + [| "+13230"; "-0"; "1,390,146"; "$190,235,421,127" + "0xFA1B"; "163042"; "-10"; "14065839182" + "16e07"; "134985.0"; "-12034" |] +for value in values do + try + let number = UInt64.Parse value + printfn $"{value} --> {number}" + with + | :? FormatException -> + printfn $"{value}: Bad Format" + | :? OverflowException -> + printfn $"{value}: Overflow" +// The example displays the following output: +// +13230 --> 13230 +// -0 --> 0 +// 1,390,146: Bad Format +// $190,235,421,127: Bad Format +// 0xFA1B: Bad Format +// 163042 --> 163042 +// -10: Overflow +// 14065839182 --> 14065839182 +// 16e07: Bad Format +// 134985.0: Bad Format +// -12034: Overflow +// \ No newline at end of file diff --git a/snippets/fsharp/System/UInt64/Parse/parseex2.fs b/snippets/fsharp/System/UInt64/Parse/parseex2.fs new file mode 100644 index 00000000000..5e1d7c89328 --- /dev/null +++ b/snippets/fsharp/System/UInt64/Parse/parseex2.fs @@ -0,0 +1,93 @@ +module parseex2 + +// +open System +open System.Globalization + +let values = + [| " 214309 "; "1,064,181"; "(0)"; "10241+"; " + 21499 " + " +21499 "; "122153.00"; "1e03ff"; "91300.0e-2" |] +let whitespace = NumberStyles.AllowLeadingWhite ||| NumberStyles.AllowTrailingWhite +let styles = + [| NumberStyles.None; whitespace + NumberStyles.AllowLeadingSign ||| NumberStyles.AllowTrailingSign ||| whitespace + NumberStyles.AllowThousands ||| NumberStyles.AllowCurrencySymbol + NumberStyles.AllowExponent ||| NumberStyles.AllowDecimalPoint |] + +// Attempt to convert each number using each style combination. +for value in values do + printfn $"Attempting to convert '{value}':" + for style in styles do + try + let number = UInt64.Parse(value, style) + printfn $" {style}: {number}" + with + | :? FormatException -> + printfn $" {style}: Bad Format" + | :? OverflowException -> + printfn $" {value}: Overflow" + printfn "" +// The example displays the following output: +// Attempting to convert ' 214309 ': +// None: Bad Format +// AllowLeadingWhite, AllowTrailingWhite: 214309 +// Integer, AllowTrailingSign: 214309 +// AllowThousands, AllowCurrencySymbol: Bad Format +// AllowDecimalPoint, AllowExponent: Bad Format +// +// Attempting to convert '1,064,181': +// None: Bad Format +// AllowLeadingWhite, AllowTrailingWhite: Bad Format +// Integer, AllowTrailingSign: Bad Format +// AllowThousands, AllowCurrencySymbol: 1064181 +// AllowDecimalPoint, AllowExponent: Bad Format +// +// Attempting to convert '(0)': +// None: Bad Format +// AllowLeadingWhite, AllowTrailingWhite: Bad Format +// Integer, AllowTrailingSign: Bad Format +// AllowThousands, AllowCurrencySymbol: Bad Format +// AllowDecimalPoint, AllowExponent: Bad Format +// +// Attempting to convert '10241+': +// None: Bad Format +// AllowLeadingWhite, AllowTrailingWhite: Bad Format +// Integer, AllowTrailingSign: 10241 +// AllowThousands, AllowCurrencySymbol: Bad Format +// AllowDecimalPoint, AllowExponent: Bad Format +// +// Attempting to convert ' + 21499 ': +// None: Bad Format +// AllowLeadingWhite, AllowTrailingWhite: Bad Format +// Integer, AllowTrailingSign: Bad Format +// AllowThousands, AllowCurrencySymbol: Bad Format +// AllowDecimalPoint, AllowExponent: Bad Format +// +// Attempting to convert ' +21499 ': +// None: Bad Format +// AllowLeadingWhite, AllowTrailingWhite: Bad Format +// Integer, AllowTrailingSign: 21499 +// AllowThousands, AllowCurrencySymbol: Bad Format +// AllowDecimalPoint, AllowExponent: Bad Format +// +// Attempting to convert '122153.00': +// None: Bad Format +// AllowLeadingWhite, AllowTrailingWhite: Bad Format +// Integer, AllowTrailingSign: Bad Format +// AllowThousands, AllowCurrencySymbol: Bad Format +// AllowDecimalPoint, AllowExponent: 122153 +// +// Attempting to convert '1e03ff': +// None: Bad Format +// AllowLeadingWhite, AllowTrailingWhite: Bad Format +// Integer, AllowTrailingSign: Bad Format +// AllowThousands, AllowCurrencySymbol: Bad Format +// AllowDecimalPoint, AllowExponent: Bad Format +// +// Attempting to convert '91300.0e-2': +// None: Bad Format +// AllowLeadingWhite, AllowTrailingWhite: Bad Format +// Integer, AllowTrailingSign: Bad Format +// AllowThousands, AllowCurrencySymbol: Bad Format +// AllowDecimalPoint, AllowExponent: 913 +// \ No newline at end of file diff --git a/snippets/fsharp/System/UInt64/Parse/parseex4.fs b/snippets/fsharp/System/UInt64/Parse/parseex4.fs new file mode 100644 index 00000000000..fb8b0dcdfea --- /dev/null +++ b/snippets/fsharp/System/UInt64/Parse/parseex4.fs @@ -0,0 +1,63 @@ +module parseex4 + +// +open System +open System.Globalization + +let cultureNames = [| "en-US"; "fr-FR" |] +let styles = [| NumberStyles.Integer; NumberStyles.Integer ||| NumberStyles.AllowDecimalPoint |] +let values = + [| "170209"; "+170209.0"; "+170209,0"; "-103214.00" + "-103214,00"; "104561.1"; "104561,1" |] + +// Parse strings using each culture +for cultureName in cultureNames do + let ci = CultureInfo cultureName + printfn $"Parsing strings using the {ci.DisplayName} culture" + // Use each style. + for style in styles do + printfn $" Style: {style}" + // Parse each numeric string. + for value in values do + try + printfn $" Converted '{value}' to {UInt64.Parse(value, style, ci)}." + with + | :? FormatException -> + printfn $" Unable to parse '{value}'." + | :? OverflowException -> + printfn $" '{value}' is out of range of the UInt64 type." +// The example displays the following output: +// Style: Integer +// Converted '170209' to 170209. +// Unable to parse '+170209.0'. +// Unable to parse '+170209,0'. +// Unable to parse '-103214.00'. +// Unable to parse '-103214,00'. +// Unable to parse '104561.1'. +// Unable to parse '104561,1'. +// Style: Integer, AllowDecimalPoint +// Converted '170209' to 170209. +// Converted '+170209.0' to 170209. +// Unable to parse '+170209,0'. +// '-103214.00' is out of range of the UInt64 type. +// Unable to parse '-103214,00'. +// '104561.1' is out of range of the UInt64 type. +// Unable to parse '104561,1'. +// Parsing strings using the French (France) culture +// Style: Integer +// Converted '170209' to 170209. +// Unable to parse '+170209.0'. +// Unable to parse '+170209,0'. +// Unable to parse '-103214.00'. +// Unable to parse '-103214,00'. +// Unable to parse '104561.1'. +// Unable to parse '104561,1'. +// Style: Integer, AllowDecimalPoint +// Converted '170209' to 170209. +// Unable to parse '+170209.0'. +// Converted '+170209,0' to 170209. +// Unable to parse '-103214.00'. +// '-103214,00' is out of range of the UInt64 type. +// Unable to parse '104561.1'. +// '104561,1' is out of range of the UInt64 type. +// \ No newline at end of file diff --git a/snippets/fsharp/System/UInt64/ToString/fs.fsproj b/snippets/fsharp/System/UInt64/ToString/fs.fsproj new file mode 100644 index 00000000000..ed4c453826d --- /dev/null +++ b/snippets/fsharp/System/UInt64/ToString/fs.fsproj @@ -0,0 +1,13 @@ + + + Exe + net6.0 + + + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/UInt64/ToString/tostring1.fs b/snippets/fsharp/System/UInt64/ToString/tostring1.fs new file mode 100644 index 00000000000..da7dd0b2ad1 --- /dev/null +++ b/snippets/fsharp/System/UInt64/ToString/tostring1.fs @@ -0,0 +1,22 @@ +module tostring1 + +// +let value = 163249057uL +// Display value using default ToString method. +printfn $"{value.ToString()}\n" + +// Define an array of format specifiers. +let formats = [| "G"; "C"; "D"; "F"; "N"; "X" |] +// Display value using the standard format specifiers. +for format in formats do + printfn $"{format} format specifier: {value.ToString format,16}" +// The example displays the following output: +// 163249057 +// +// G format specifier: 163249057 +// C format specifier: $163,249,057.00 +// D format specifier: 163249057 +// F format specifier: 163249057.00 +// N format specifier: 163,249,057.00 +// X format specifier: 9BAFBA1 +// \ No newline at end of file diff --git a/snippets/fsharp/System/UInt64/ToString/tostring2.fs b/snippets/fsharp/System/UInt64/ToString/tostring2.fs new file mode 100644 index 00000000000..40459a92f7e --- /dev/null +++ b/snippets/fsharp/System/UInt64/ToString/tostring2.fs @@ -0,0 +1,23 @@ +module tostring2 + +// +open System.Globalization + +let getName (ci: CultureInfo) = + if ci.Equals CultureInfo.InvariantCulture then "Invariant" + else ci.Name + +// Define an array of CultureInfo objects. +let ci = + [| CultureInfo "en-US" + CultureInfo "fr-FR" + CultureInfo.InvariantCulture |] + +let value = 18709243uL + +printfn $" {getName ci[0],12} {getName ci[1],12} {getName ci[2],12}" +printfn $" {value.ToString ci[0],12} {value.ToString ci[1],12} {value.ToString ci[2],12}" +// The example displays the following output: +// en-US fr-FR Invariant +// 18709243 18709243 18709243 +// \ No newline at end of file diff --git a/snippets/fsharp/System/UInt64/ToString/tostring3.fs b/snippets/fsharp/System/UInt64/ToString/tostring3.fs new file mode 100644 index 00000000000..b391a036a4d --- /dev/null +++ b/snippets/fsharp/System/UInt64/ToString/tostring3.fs @@ -0,0 +1,25 @@ +module tostring3 + +// +let value = 217960834uL +let specifiers = + [| "G"; "C"; "D3"; "E2"; "e3"; "F" + "N"; "P"; "X"; "000000.0"; "#.0" + "00000000(0)**Zero**" |] + +for specifier in specifiers do + printfn $"{specifier}: {value.ToString specifier}" +// The example displays the following output: +// G: 217960834 +// C: $217,960,834.00 +// D3: 217960834 +// E2: 2.18E+008 +// e3: 2.180e+008 +// F: 217960834.00 +// N: 217,960,834.00 +// P: 21,796,083,400.00 % +// X: CFDD182 +// 000000.0: 217960834.0 +// #.0: 217960834.0 +// 00000000(0)**Zero**: 217960834 +// \ No newline at end of file diff --git a/snippets/fsharp/System/UInt64/ToString/tostring4.fs b/snippets/fsharp/System/UInt64/ToString/tostring4.fs new file mode 100644 index 00000000000..c97433b88ce --- /dev/null +++ b/snippets/fsharp/System/UInt64/ToString/tostring4.fs @@ -0,0 +1,50 @@ +module tostring4 + +// +open System.Globalization + +// Define cultures whose formatting conventions are to be used. +let cultures = + [| CultureInfo.CreateSpecificCulture "en-US" + CultureInfo.CreateSpecificCulture "fr-FR" + CultureInfo.CreateSpecificCulture "es-ES" |] +let specifiers = [| "G"; "C"; "D4"; "E2"; "F"; "N"; "P"; "X2" |] +let value = 22224021uL + +for specifier in specifiers do + for culture in cultures do + printfn $"{specifier,2} format using {culture.Name} culture: {value.ToString(specifier, culture), 18}" + printfn "" +// The example displays the following output: +// G format using en-US culture: 22224021 +// G format using fr-FR culture: 22224021 +// G format using es-ES culture: 22224021 +// +// C format using en-US culture: $22,224,021.00 +// C format using fr-FR culture: 22 224 021,00 € +// C format using es-ES culture: 22.224.021,00 € +// +// D4 format using en-US culture: 22224021 +// D4 format using fr-FR culture: 22224021 +// D4 format using es-ES culture: 22224021 +// +// E2 format using en-US culture: 2.22E+007 +// E2 format using fr-FR culture: 2,22E+007 +// E2 format using es-ES culture: 2,22E+007 +// +// F format using en-US culture: 22224021.00 +// F format using fr-FR culture: 22224021,00 +// F format using es-ES culture: 22224021,00 +// +// N format using en-US culture: 22,224,021.00 +// N format using fr-FR culture: 22 224 021,00 +// N format using es-ES culture: 22.224.021,00 +// +// P format using en-US culture: 2,222,402,100.00 % +// P format using fr-FR culture: 2 222 402 100,00 % +// P format using es-ES culture: 2.222.402.100,00 % +// +// X2 format using en-US culture: 1531C95 +// X2 format using fr-FR culture: 1531C95 +// X2 format using es-ES culture: 1531C95 +// \ No newline at end of file diff --git a/snippets/fsharp/System/UInt64/TryParse/fs.fsproj b/snippets/fsharp/System/UInt64/TryParse/fs.fsproj new file mode 100644 index 00000000000..082dd47f2be --- /dev/null +++ b/snippets/fsharp/System/UInt64/TryParse/fs.fsproj @@ -0,0 +1,11 @@ + + + Exe + net6.0 + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/UInt64/TryParse/tryparse1.fs b/snippets/fsharp/System/UInt64/TryParse/tryparse1.fs new file mode 100644 index 00000000000..a205e7daa89 --- /dev/null +++ b/snippets/fsharp/System/UInt64/TryParse/tryparse1.fs @@ -0,0 +1,30 @@ +module tryparse1 + +// +open System + +let numericStrings = + [| "1293.8"; "+1671.7"; "28347." + " 33113684 "; "(0)"; "-0"; "+1293617" + "18-"; "119870"; "31,024"; " 3127094 " + "00700000" |] +for numericString in numericStrings do + match UInt64.TryParse numericString with + | true, number -> + printfn $"Converted '{numericString}' to {number}." + | _ -> + printfn $"Cannot convert '{numericString}' to a UInt64." +// The example displays the following output: +// Cannot convert '1293.8' to a UInt64. +// Cannot convert '+1671.7' to a UInt64. +// Cannot convert '28347.' to a UInt64. +// Converted ' 33113684 ' to 33113684. +// Cannot convert '(0)' to a UInt64. +// Converted '-0' to 0. +// Converted '+1293617' to 1293617. +// Cannot convert '18-' to a UInt64. +// Converted '119870' to 119870. +// Cannot convert '31,024' to a UInt64. +// Converted ' 3127094 ' to 3127094. +// Converted '0070000' to 70000. +// \ No newline at end of file diff --git a/snippets/fsharp/System/UInt64/TryParse/tryparse2.fs b/snippets/fsharp/System/UInt64/TryParse/tryparse2.fs new file mode 100644 index 00000000000..d371895cd0c --- /dev/null +++ b/snippets/fsharp/System/UInt64/TryParse/tryparse2.fs @@ -0,0 +1,56 @@ +module tryparse2 + +// +open System +open System.Globalization + +let callTryParse (stringToConvert: string) (styles: NumberStyles) = + match UInt64.TryParse(stringToConvert, styles, CultureInfo.InvariantCulture) with + | true, number -> + printfn $"Converted '{stringToConvert}' to {number}." + | _ -> + printfn $"Attempted conversion of '{stringToConvert}' failed." + +do + let numericString = "2106034" + let styles = NumberStyles.Integer + callTryParse numericString styles + + let numericString = "-10603" + let styles = NumberStyles.None + callTryParse numericString styles + + let numericString = "29103674.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 = "41792210E-01" + let styles = NumberStyles.Integer ||| NumberStyles.AllowExponent + callTryParse numericString styles + + let numericString = "9112E-01" + callTryParse numericString styles + + let numericString = "312E01" + callTryParse numericString styles + + let numericString = "FFC86DA1" + callTryParse numericString NumberStyles.HexNumber + + let numericString = "0x8F8C" + callTryParse numericString NumberStyles.HexNumber +// The example displays the following output: +// Converted '2106034' to 2106034. +// Attempted conversion of '-10603' failed. +// Converted '29103674.00' to 29103674. +// Attempted conversion of '10345.72' failed. +// Converted '41792210E-01' to 4179221. +// Attempted conversion of '9112E-01' failed. +// Converted '312E01' to 3120. +// Converted 'FFC86DA1' to 4291325345. +// Attempted conversion of '0x8F8C' failed. +// \ No newline at end of file diff --git a/xml/System/UInt64.xml b/xml/System/UInt64.xml index c7846af7b9c..93bb9bdcc89 100644 --- a/xml/System/UInt64.xml +++ b/xml/System/UInt64.xml @@ -344,6 +344,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/UInt64 Example/CPP/source.cpp" id="Snippet3"::: :::code language="csharp" source="~/snippets/csharp/System/UInt64/CompareTo/source.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/UInt64/CompareTo/source.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/UInt64 Example/VB/source.vb" id="Snippet3"::: ]]> @@ -435,6 +436,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/T.CompareTo/CPP/cat.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Boolean/CompareTo/cat.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/CompareTo/cat.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/T.CompareTo/VB/cat.vb" id="Snippet1"::: ]]> @@ -514,6 +516,7 @@ The following example demonstrates the method. :::code language="csharp" source="~/snippets/csharp/System/UInt64/Equals/equals1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/UInt64/Equals/equals1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.uint64.equals/vb/equals1.vb" id="Snippet1"::: ]]> @@ -522,6 +525,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 a 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 a 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="~/snippets/csharp/System/UInt64/Equals/equalsoverl.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/UInt64/Equals/equalsoverl.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.uint64.equals/vb/equalsoverl.vb" id="Snippet2"::: @@ -586,6 +590,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/UInt64_Equals/CPP/uint64_equals.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/UInt64/Equals/uint64_equals.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/UInt64/Equals/uint64_equals.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/UInt64_Equals/VB/uint64_equals.vb" id="Snippet1"::: ]]> @@ -594,6 +599,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 a 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 a 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="~/snippets/csharp/System/UInt64/Equals/equalsoverl.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/UInt64/Equals/equalsoverl.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.uint64.equals/vb/equalsoverl.vb" id="Snippet2"::: @@ -735,6 +741,7 @@ The following example uses the and fields to verify that a value is within the range of the type before it performs a type conversion. This prevents an at run time. :::code language="csharp" source="~/snippets/csharp/System/UInt64/MaxValue/MaxValue1.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/UInt64/MaxValue/MaxValue1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.UInt64.MaxValue/vb/MaxValue1.vb" id="Snippet1"::: ]]> @@ -793,6 +800,7 @@ The following example uses the and fields to verify that a value is within the range of the type before it performs a type conversion. This prevents an at run time. :::code language="csharp" source="~/snippets/csharp/System/UInt64/MaxValue/MaxValue1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/UInt64/MaxValue/MaxValue1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.UInt64.MaxValue/vb/MaxValue1.vb" id="Snippet1"::: ]]> @@ -890,6 +898,7 @@ The following example uses the method to parse an array of string values. :::code language="csharp" source="~/snippets/csharp/System/UInt64/Parse/parse1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/UInt64/Parse/parse1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.uint64.parse/vb/parse1.vb" id="Snippet1"::: ]]> @@ -1015,6 +1024,7 @@ The following example tries to parse each element in a string array by using a number of values. :::code language="csharp" source="~/snippets/csharp/System/UInt64/Parse/parseex2.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/UInt64/Parse/parseex2.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.uint64.parse/vb/parseex2.vb" id="Snippet2"::: ]]> @@ -1315,6 +1325,7 @@ The following example uses the method to convert various string representations of numbers to 64-bit unsigned integer values. :::code language="csharp" source="~/snippets/csharp/System/UInt64/Parse/parseex4.cs" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System/UInt64/Parse/parseex4.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.uint64.parse/vb/parseex4.vb" id="Snippet4"::: ]]> @@ -2329,6 +2340,7 @@ This member is an explicit interface member implementation. It can be used only The following example displays a value by using the default method. It also displays the string representations of the value that results from using some standard format specifiers. The examples are displayed using the formatting conventions of the en-US culture. :::code language="csharp" source="~/snippets/csharp/System/UInt64/ToString/tostring1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/UInt64/ToString/tostring1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.uint64.tostring/vb/tostring1.vb" id="Snippet1"::: ]]> @@ -2412,6 +2424,7 @@ This member is an explicit interface member implementation. It can be used only The following example formats a 64-bit signed integer value by using several format providers, including one for the invariant culture. The output from the example illustrates that the formatted string returned by the method is the same regardless of the format provider. :::code language="csharp" source="~/snippets/csharp/System/UInt64/ToString/tostring2.cs" interactive="try-dotnet" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/UInt64/ToString/tostring2.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.uint64.tostring/vb/tostring2.vb" id="Snippet2"::: ]]> @@ -2498,6 +2511,7 @@ This member is an explicit interface member implementation. It can be used only The following example displays a 64-bit unsigned integer value by using each standard format string and some custom format strings. :::code language="csharp" source="~/snippets/csharp/System/UInt64/ToString/tostring3.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/UInt64/ToString/tostring3.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.uint64.tostring/vb/tostring3.vb" id="Snippet3"::: ]]> @@ -2599,6 +2613,7 @@ This member is an explicit interface member implementation. It can be used only The following example displays a 32-bit unsigned integer value by using the standard numeric format specifiers and a number of specific objects. :::code language="csharp" source="~/snippets/csharp/System/UInt64/ToString/tostring4.cs" interactive="try-dotnet" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System/UInt64/ToString/tostring4.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.uint64.tostring/vb/tostring4.vb" id="Snippet4"::: ]]> @@ -2816,6 +2831,7 @@ This member is an explicit interface member implementation. It can be used only The following example calls the method once for each element in a string array. :::code language="csharp" source="~/snippets/csharp/System/UInt64/TryParse/tryparse1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/UInt64/TryParse/tryparse1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.uint64.tryparse/vb/tryparse1.vb" id="Snippet1"::: ]]> @@ -3017,6 +3033,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 strings and values. :::code language="csharp" source="~/snippets/csharp/System/UInt64/TryParse/tryparse2.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/UInt64/TryParse/tryparse2.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.uint64.tryparse/vb/tryparse2.vb" id="Snippet2"::: ]]>