From cdd065e35df86be8fc73f2827fd6438666ab03b1 Mon Sep 17 00:00:00 2001 From: kevincathcart-cas <72209838+kevincathcart-cas@users.noreply.github.com> Date: Tue, 18 Jun 2024 13:47:49 -0400 Subject: [PATCH 01/10] Clarify null name for IOptions related types --- xml/Microsoft.Extensions.Options/IOptionsMonitor`1.xml | 2 +- xml/Microsoft.Extensions.Options/IOptionsSnapshot`1.xml | 2 +- xml/Microsoft.Extensions.Options/OptionsManager`1.xml | 2 +- xml/Microsoft.Extensions.Options/OptionsMonitor`1.xml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/xml/Microsoft.Extensions.Options/IOptionsMonitor`1.xml b/xml/Microsoft.Extensions.Options/IOptionsMonitor`1.xml index 55f66475b26..ec3046cf791 100644 --- a/xml/Microsoft.Extensions.Options/IOptionsMonitor`1.xml +++ b/xml/Microsoft.Extensions.Options/IOptionsMonitor`1.xml @@ -97,7 +97,7 @@ - The name of the instance, if is . + The name of the instance. Uses if is provided. Returns a configured instance with the given name. The instance that matches the given . To be added. diff --git a/xml/Microsoft.Extensions.Options/IOptionsSnapshot`1.xml b/xml/Microsoft.Extensions.Options/IOptionsSnapshot`1.xml index 095460422f9..7f80d5fcede 100644 --- a/xml/Microsoft.Extensions.Options/IOptionsSnapshot`1.xml +++ b/xml/Microsoft.Extensions.Options/IOptionsSnapshot`1.xml @@ -76,7 +76,7 @@ - The name of the instance, if is . + The name of the instance. Uses if is provided. Returns a configured instance with the given name. The instance that matches the given . To be added. diff --git a/xml/Microsoft.Extensions.Options/OptionsManager`1.xml b/xml/Microsoft.Extensions.Options/OptionsManager`1.xml index 4a76fa29fd7..9d1fa6c6e1c 100644 --- a/xml/Microsoft.Extensions.Options/OptionsManager`1.xml +++ b/xml/Microsoft.Extensions.Options/OptionsManager`1.xml @@ -112,7 +112,7 @@ - The name of the instance, if is . + The name of the instance. Uses if is provided. Returns a configured instance with the given . The instance that matches the given . To be added. diff --git a/xml/Microsoft.Extensions.Options/OptionsMonitor`1.xml b/xml/Microsoft.Extensions.Options/OptionsMonitor`1.xml index 42ed3876b01..acec5e309a7 100644 --- a/xml/Microsoft.Extensions.Options/OptionsMonitor`1.xml +++ b/xml/Microsoft.Extensions.Options/OptionsMonitor`1.xml @@ -167,7 +167,7 @@ - The name of the instance, if a is used. + The name of the instance. Uses if is provided. Returns a configured instance with the given . The instance that matches the given . To be added. From c12615d6f4e719b30569bb0c8ff7c95826c9b8b7 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Mon, 24 Jun 2024 07:20:10 -0700 Subject: [PATCH 02/10] fix try.net links (#10048) --- includes/csharp-interactive-with-utc-note.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/csharp-interactive-with-utc-note.md b/includes/csharp-interactive-with-utc-note.md index 51c6371c670..0a10a1a202e 100644 --- a/includes/csharp-interactive-with-utc-note.md +++ b/includes/csharp-interactive-with-utc-note.md @@ -1,5 +1,5 @@ > [!NOTE] -> Some C# examples in this article run in the [Try.NET](https://try.dot.net) inline code runner and playground. Select the **Run** button to run an example in an interactive window. Once you execute the code, you can modify it and run the modified code by selecting **Run** again. The modified code either runs in the interactive window or, if compilation fails, the interactive window displays all C# compiler error messages. -> -> The [local time zone](xref:System.TimeZoneInfo.Local) of the [Try.NET](https://try.dot.net) inline code runner and playground is Coordinated Universal Time, or UTC. This may affect the behavior and the output of examples that illustrate the , , and types and their members. +> Some C# examples in this article run in the [Try.NET](https://github.com/dotnet/try) inline code runner and playground. Select **Run** to run an example in an interactive window. Once you execute the code, you can modify it and run the modified code by selecting **Run** again. The modified code either runs in the interactive window or, if compilation fails, the interactive window displays all C# compiler error messages. +> +> The [local time zone](xref:System.TimeZoneInfo.Local) of the [Try.NET](https://github.com/dotnet/try) inline code runner and playground is Coordinated Universal Time, or UTC. This might affect the behavior and the output of examples that illustrate the , , and types and their members. From fca2b36ab308b82949031057e91414e980744006 Mon Sep 17 00:00:00 2001 From: Albert Du <52804499+albert-du@users.noreply.github.com> Date: Mon, 24 Jun 2024 07:21:29 -0700 Subject: [PATCH 03/10] F# snippets (#10049) --- .../BigInteger/.ctor/Example1.fs | 74 ++++ .../BigInteger/.ctor/Example2.fs | 130 ++++++ .../BigInteger/.ctor/fs.fsproj | 11 + .../BigInteger/Add/Multiply1.fs | 32 ++ .../System.Numerics/BigInteger/Add/fs.fsproj | 10 + .../BigInteger/Compare/Compare1.fs | 16 + .../BigInteger/Compare/fs.fsproj | 10 + .../BigInteger/CompareTo/Example1.fs | 52 +++ .../BigInteger/CompareTo/Example2.fs | 62 +++ .../BigInteger/CompareTo/fs.fsproj | 11 + .../BigInteger/Divide/Divide1.fs | 62 +++ .../BigInteger/Divide/fs.fsproj | 10 + .../BigInteger/Equals/EqualsExample1.fs | 85 ++++ .../BigInteger/Equals/Equals_Obj1.fs | 23 + .../BigInteger/Equals/fs.fsproj | 11 + .../BigInteger_Examples.fs | 340 ++++++++++++++ .../GreatestCommonDivisor/fs.fsproj | 10 + .../BigInteger/LogMethod/fs.fsproj | 10 + .../BigInteger/LogMethod/log1.fs | 18 + .../System.Numerics/BigInteger/Max/Max1.fs | 39 ++ .../System.Numerics/BigInteger/Max/fs.fsproj | 10 + .../System.Numerics/BigInteger/Min/Min1.fs | 41 ++ .../System.Numerics/BigInteger/Min/fs.fsproj | 10 + .../BigInteger/ModPow/ModPow1.fs | 10 + .../BigInteger/ModPow/fs.fsproj | 10 + .../BigInteger/Parse/Parse1.fs | 100 +++++ .../BigInteger/Parse/ParseHex1.fs | 37 ++ .../Parse/System.Numeric.BigInteger.Parse.fs | 130 ++++++ .../BigInteger/Parse/fs.fsproj | 12 + .../BigInteger/Remainder/Remainder1.fs | 42 ++ .../BigInteger/Remainder/fs.fsproj | 10 + .../BigInteger/ToByteArray/ToByteArray1.fs | 38 ++ .../BigInteger/ToByteArray/fs.fsproj | 10 + .../System.Numeric.BigInteger.ToString.fs | 42 ++ .../BigInteger/ToString/ToString1.fs | 163 +++++++ .../BigInteger/ToString/fs.fsproj | 11 + .../System.Numeric.BigInteger.TryParse.fs | 102 +++++ .../BigInteger/TryParse/TryParse1.fs | 99 +++++ .../BigInteger/TryParse/TryParseHex1.fs | 39 ++ .../BigInteger/TryParse/fs.fsproj | 12 + .../BigInteger/op_BitwiseAnd/Operator1.fs | 416 ++++++++++++++++++ .../BigInteger/op_BitwiseAnd/RightShift1.fs | 68 +++ .../BigInteger/op_BitwiseAnd/fs.fsproj | 11 + .../BigInteger/op_Explicit/Explicit1.fs | 135 ++++++ .../System.Numeric.BigInteger.Explicit.fs | 237 ++++++++++ .../BigInteger/op_Explicit/fs.fsproj | 11 + .../BigInteger/op_Implicit/Implicit1.fs | 92 ++++ .../BigInteger/op_Implicit/fs.fsproj | 10 + .../op_OnesComplement/OnesComplement1.fs | 32 ++ .../BigInteger/op_OnesComplement/fs.fsproj | 10 + xml/System.Numerics/BigInteger.xml | 125 ++++++ 51 files changed, 3091 insertions(+) create mode 100644 snippets/fsharp/System.Numerics/BigInteger/.ctor/Example1.fs create mode 100644 snippets/fsharp/System.Numerics/BigInteger/.ctor/Example2.fs create mode 100644 snippets/fsharp/System.Numerics/BigInteger/.ctor/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/BigInteger/Add/Multiply1.fs create mode 100644 snippets/fsharp/System.Numerics/BigInteger/Add/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/BigInteger/Compare/Compare1.fs create mode 100644 snippets/fsharp/System.Numerics/BigInteger/Compare/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/BigInteger/CompareTo/Example1.fs create mode 100644 snippets/fsharp/System.Numerics/BigInteger/CompareTo/Example2.fs create mode 100644 snippets/fsharp/System.Numerics/BigInteger/CompareTo/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/BigInteger/Divide/Divide1.fs create mode 100644 snippets/fsharp/System.Numerics/BigInteger/Divide/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/BigInteger/Equals/EqualsExample1.fs create mode 100644 snippets/fsharp/System.Numerics/BigInteger/Equals/Equals_Obj1.fs create mode 100644 snippets/fsharp/System.Numerics/BigInteger/Equals/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.fs create mode 100644 snippets/fsharp/System.Numerics/BigInteger/GreatestCommonDivisor/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/BigInteger/LogMethod/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/BigInteger/LogMethod/log1.fs create mode 100644 snippets/fsharp/System.Numerics/BigInteger/Max/Max1.fs create mode 100644 snippets/fsharp/System.Numerics/BigInteger/Max/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/BigInteger/Min/Min1.fs create mode 100644 snippets/fsharp/System.Numerics/BigInteger/Min/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/BigInteger/ModPow/ModPow1.fs create mode 100644 snippets/fsharp/System.Numerics/BigInteger/ModPow/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/BigInteger/Parse/Parse1.fs create mode 100644 snippets/fsharp/System.Numerics/BigInteger/Parse/ParseHex1.fs create mode 100644 snippets/fsharp/System.Numerics/BigInteger/Parse/System.Numeric.BigInteger.Parse.fs create mode 100644 snippets/fsharp/System.Numerics/BigInteger/Parse/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/BigInteger/Remainder/Remainder1.fs create mode 100644 snippets/fsharp/System.Numerics/BigInteger/Remainder/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/BigInteger/ToByteArray/ToByteArray1.fs create mode 100644 snippets/fsharp/System.Numerics/BigInteger/ToByteArray/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/BigInteger/ToString/System.Numeric.BigInteger.ToString.fs create mode 100644 snippets/fsharp/System.Numerics/BigInteger/ToString/ToString1.fs create mode 100644 snippets/fsharp/System.Numerics/BigInteger/ToString/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/BigInteger/TryParse/System.Numeric.BigInteger.TryParse.fs create mode 100644 snippets/fsharp/System.Numerics/BigInteger/TryParse/TryParse1.fs create mode 100644 snippets/fsharp/System.Numerics/BigInteger/TryParse/TryParseHex1.fs create mode 100644 snippets/fsharp/System.Numerics/BigInteger/TryParse/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.fs create mode 100644 snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/RightShift1.fs create mode 100644 snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/BigInteger/op_Explicit/Explicit1.fs create mode 100644 snippets/fsharp/System.Numerics/BigInteger/op_Explicit/System.Numeric.BigInteger.Explicit.fs create mode 100644 snippets/fsharp/System.Numerics/BigInteger/op_Explicit/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/BigInteger/op_Implicit/Implicit1.fs create mode 100644 snippets/fsharp/System.Numerics/BigInteger/op_Implicit/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/BigInteger/op_OnesComplement/OnesComplement1.fs create mode 100644 snippets/fsharp/System.Numerics/BigInteger/op_OnesComplement/fs.fsproj diff --git a/snippets/fsharp/System.Numerics/BigInteger/.ctor/Example1.fs b/snippets/fsharp/System.Numerics/BigInteger/.ctor/Example1.fs new file mode 100644 index 00000000000..84f5bb897d8 --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/.ctor/Example1.fs @@ -0,0 +1,74 @@ +module example1 + +open System +open System.Numerics + +let createSimpleArray () = + // + let bytes = [| 5uy; 4uy; 3uy; 2uy; 1uy |] + let number = new BigInteger(bytes) + printfn $"The value of number is {number} (or 0x{number:x})." + // The example displays the following output: + // The value of number is 4328719365 (or 0x102030405). + // + +let roundtripValue () = + // + // Instantiate BigInteger values. + let positiveValue = BigInteger.Parse "4713143110832790377889" + let negativeValue = BigInteger.Add(-Int64.MaxValue, -60000) + + // Create two byte arrays. + let positiveBytes = positiveValue.ToByteArray() + let negativeBytes = negativeValue.ToByteArray() + + // Instantiate new BigInteger from negativeBytes array. + printf $"Converted {negativeValue:N0} to the byte array " + + for byteValue in negativeBytes do + printf $"0x{byteValue:x2} " + + printfn "" + let negativeValue2 = bigint negativeBytes + printfn $"Converted the byte array to {negativeValue2:N0}" + printfn "" + + // Instantiate new BigInteger from positiveBytes array. + printf $"Converted {positiveValue:N0} to the byte array " + + for byteValue in positiveBytes do + printf $"0x{byteValue:x2} " + + printfn "" + let positiveValue2 = new BigInteger(positiveBytes) + printfn $"Converted the byte array to {positiveValue2:N0}" + printfn "" + // The example displays the following output: + // Converted -9,223,372,036,854,835,807 to the byte array A1 15 FF FF FF FF FF 7F FF + // Converted the byte array to -9,223,372,036,854,835,807 + // + // Converted 4,713,143,110,832,790,377,889 to the byte array A1 15 FF FF FF FF FF 7F FF 00 + // Converted the byte array to 4,713,143,110,832,790,377,889 + // + +let ensureSign () = + // + let originalNumber = UInt64.MaxValue + let mutable bytes = BitConverter.GetBytes originalNumber + + if originalNumber > 0uL && (bytes[bytes.Length - 1] &&& 0x80uy) > 0uy then + let temp = Array.zeroCreate bytes.Length + + Array.Copy(bytes, temp, bytes.Length) + bytes <- Array.zeroCreate (temp.Length + 1) + Array.Copy(temp, bytes, temp.Length) + + let newNumber = bigint bytes + printfn $"Converted the UInt64 value {originalNumber:N0} to {newNumber:N0}." + // The example displays the following output: + // Converted the UInt64 value 18,446,744,073,709,551,615 to 18,446,744,073,709,551,615. + // + +createSimpleArray () +roundtripValue () +ensureSign () diff --git a/snippets/fsharp/System.Numerics/BigInteger/.ctor/Example2.fs b/snippets/fsharp/System.Numerics/BigInteger/.ctor/Example2.fs new file mode 100644 index 00000000000..b1b1795d0ba --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/.ctor/Example2.fs @@ -0,0 +1,130 @@ +module example2 + +open System +open System.Numerics + +let decimalConstructor () = + // + let decimalValues = [ -1790.533m; -15.1514m; 18903.79m; 9180098.003m ] + + for decimalValue in decimalValues do + let number = bigint decimalValue + printfn $"Instantiated BigInteger value {number} from the Decimal value {decimalValue}." + // The example displays the following output: + // Instantiated BigInteger value -1790 from the Decimal value -1790.533. + // Instantiated BigInteger value -15 from the Decimal value -15.1514. + // Instantiated BigInteger value 18903 from the Decimal value 18903.79. + // Instantiated BigInteger value 9180098 from the Decimal value 9180098.003. + // + +let doubleConstructor () = + // + // Create a BigInteger from a large double value. + let doubleValue = -6e20 + let bigIntValue = bigint doubleValue + printfn $"Original Double value: {doubleValue:N0}" + printfn $"Original BigInteger value: {bigIntValue:N0}" + // Increment and then display both values. + let doubleValue = doubleValue + 1. + let bigIntValue = bigIntValue + BigInteger.One + printfn $"Incremented Double value: {doubleValue:N0}" + printfn $"Incremented BigInteger value: {bigIntValue:N0}" + // The example displays the following output: + // Original Double value: -600,000,000,000,000,000,000 + // Original BigInteger value: -600,000,000,000,000,000,000 + // Incremented Double value: -600,000,000,000,000,000,000 + // Incremented BigInteger value: -599,999,999,999,999,999,999 + // + +let integerConstructor () = + // + let integers = [ Int32.MinValue; -10534; -189; 0; 17; 113439; Int32.MaxValue ] + + for number in integers do + let constructed = bigint number + let assigned = number + printfn $"{constructed} = {assigned}: {constructed.Equals assigned}" + // The example displays the following output: + // -2147483648 = -2147483648: True + // -10534 = -10534: True + // -189 = -189: True + // 0 = 0: True + // 17 = 17: True + // 113439 = 113439: True + // 2147483647 = 2147483647: True + // + +let longConstructor () = + // + let longs = [ Int64.MinValue; -10534; -189; 0; 17; 113439; Int64.MaxValue ] + + for number in longs do + let constructed = bigint number + let assigned = number + printfn $"{constructed} = {assigned}: {constructed.Equals assigned}" + // The example displays the following output: + // -2147483648 = -2147483648: True + // -10534 = -10534: True + // -189 = -189: True + // 0 = 0: True + // 17 = 17: True + // 113439 = 113439: True + // 2147483647 = 2147483647: True + // + +let singleConstructor () = + // + // Create a BigInteger from a large negative Single value + let negativeSingle = Single.MinValue + let negativeNumber = bigint negativeSingle + + printfn $"""{negativeSingle.ToString "N0"}""" + printfn $"""{negativeNumber.ToString "N0"}""" + + let negativeSingle = negativeSingle + 1f + let negativeNumber = negativeNumber + 1I + + printfn $"""{negativeSingle.ToString "N0"}""" + printfn $"""{negativeNumber.ToString "N0"}""" + // The example displays the following output: + // -340,282,300,000,000,000,000,000,000,000,000,000,000 + // -340,282,346,638,528,859,811,704,183,484,516,925,440 + // -340,282,300,000,000,000,000,000,000,000,000,000,000 + // -340,282,346,638,528,859,811,704,183,484,516,925,439 + // + +let UInt32Constructor () = + // + let unsignedValues = [ 0u; 16704u; 199365u; UInt32.MaxValue ] + + for unsignedValue in unsignedValues do + let constructedNumber = bigint unsignedValue + let assignedNumber = unsignedValue + + if constructedNumber.Equals assignedNumber then + printfn $"Both methods create a BigInteger whose value is {constructedNumber:N0}." + else + printfn $"{constructedNumber:N0} ≠ {assignedNumber:N0}" + // The example displays the following output: + // Both methods create a BigInteger whose value is 0. + // Both methods create a BigInteger whose value is 16,704. + // Both methods create a BigInteger whose value is 199,365. + // Both methods create a BigInteger whose value is 4,294,967,295. + // + +let UInt64Constructor () = + // + let unsignedValue = UInt64.MaxValue + let number = bigint unsignedValue + printfn $"{number:N0}" + // The example displays the following output: + // 18,446,744,073,709,551,615 + // + +decimalConstructor () +doubleConstructor () +integerConstructor () +longConstructor () +singleConstructor () +UInt32Constructor() +UInt64Constructor() diff --git a/snippets/fsharp/System.Numerics/BigInteger/.ctor/fs.fsproj b/snippets/fsharp/System.Numerics/BigInteger/.ctor/fs.fsproj new file mode 100644 index 00000000000..45798b3f243 --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/.ctor/fs.fsproj @@ -0,0 +1,11 @@ + + + Exe + net8.0 + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/BigInteger/Add/Multiply1.fs b/snippets/fsharp/System.Numerics/BigInteger/Add/Multiply1.fs new file mode 100644 index 00000000000..2a50d48df12 --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/Add/Multiply1.fs @@ -0,0 +1,32 @@ +open System; +open System.Numerics; + + +let multiply () = + // + let number = BigInteger.Multiply(Int64.MaxValue, 3); + // + () + +let add () = + // + let number = BigInteger.Add(Int64.MaxValue, Int32.MaxValue); + // + () + +let subtract () = + // + let number = BigInteger.Subtract(Int64.MinValue, Int64.MaxValue); + // + () + +let negate () = + // + let number = BigInteger.Negate Int64.MinValue + // + () + +multiply(); +add(); +subtract(); +negate(); \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/BigInteger/Add/fs.fsproj b/snippets/fsharp/System.Numerics/BigInteger/Add/fs.fsproj new file mode 100644 index 00000000000..3c7572ac3c9 --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/Add/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/BigInteger/Compare/Compare1.fs b/snippets/fsharp/System.Numerics/BigInteger/Compare/Compare1.fs new file mode 100644 index 00000000000..be61ec7bbe1 --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/Compare/Compare1.fs @@ -0,0 +1,16 @@ +open System +open System.Numerics + +// +let number1 = BigInteger.Pow(int64 System.Int64.MaxValue, 100) +let number2 = number1 + 1I +let relation = + match BigInteger.Compare(number1, number2) with + | -1 -> "<" + | 0 -> "=" + | 1 | _ -> ">" + +printfn $"{number1} {relation} {number2}" +// The example displays the following output: +// 3.0829940252776347122742186219E+1896 < 3.0829940252776347122742186219E+1896 +// diff --git a/snippets/fsharp/System.Numerics/BigInteger/Compare/fs.fsproj b/snippets/fsharp/System.Numerics/BigInteger/Compare/fs.fsproj new file mode 100644 index 00000000000..4e092b1e066 --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/Compare/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/BigInteger/CompareTo/Example1.fs b/snippets/fsharp/System.Numerics/BigInteger/CompareTo/Example1.fs new file mode 100644 index 00000000000..2c1af4231e2 --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/CompareTo/Example1.fs @@ -0,0 +1,52 @@ +module example1 + +// +open System +open System.Numerics + +[] +type StarInfo = + // Define fields + val Name: string + val Distance: BigInteger + + // Define constructors. + new(name, lightYears) = + { Name = name + // Calculate distance in miles from light years. + Distance = lightYears * 5.88e12 |> bigint } + + new(name, distance) = { Name = name; Distance = distance } + + // Display name of star and its distance in parentheses. + override this.ToString() = + $"{this.Name, -10} ({this.Distance:N0})" + + interface IComparable with + // Compare StarInfo objects by their distance from Earth. + member this.CompareTo(other: StarInfo) = this.Distance.CompareTo(other.Distance) +// + +// +let stars = ResizeArray() + +let star1 = StarInfo("Sirius", 8.6) +stars.Add(star1) +let star2 = StarInfo("Rigel", 1400.) +stars.Add(star2) +let star3 = StarInfo("Castor", 49.) +stars.Add(star3) +let star4 = StarInfo("Antares", 520.) +stars.Add(star4) + +stars.Sort() + +for star in stars do + printfn $"{star}" + +// The example displays the following output: +// Sirius (50,568,000,000,000) +// Castor (288,120,000,000,000) +// Antares (3,057,600,000,000,000) +// Rigel (8,232,000,000,000,000) +// diff --git a/snippets/fsharp/System.Numerics/BigInteger/CompareTo/Example2.fs b/snippets/fsharp/System.Numerics/BigInteger/CompareTo/Example2.fs new file mode 100644 index 00000000000..f80b1f82fbb --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/CompareTo/Example2.fs @@ -0,0 +1,62 @@ +module example2 + +open System +open System.Numerics + +let compareToLong () = + // + let bigIntValue = BigInteger.Parse "3221123045552" + + let byteValue = 16uy + let sbyteValue = -16y + let shortValue = 1233s + let ushortValue = 1233us + let intValue = -12233 + let uintValue = 12233u + let longValue = 12382222L + let ulongValue = 1238222UL + + printfn $"Comparing {bigIntValue} with {byteValue}: {bigIntValue.CompareTo byteValue}" + printfn $"Comparing {bigIntValue} with {sbyteValue}: {bigIntValue.CompareTo sbyteValue}" + printfn $"Comparing {bigIntValue} with {shortValue}: {bigIntValue.CompareTo shortValue}" + printfn $"Comparing {bigIntValue} with {ushortValue}: {bigIntValue.CompareTo ushortValue}" + printfn $"Comparing {bigIntValue} with {intValue}: {bigIntValue.CompareTo intValue}" + printfn $"Comparing {bigIntValue} with {uintValue}: {bigIntValue.CompareTo uintValue}" + printfn $"Comparing {bigIntValue} with {longValue}: {bigIntValue.CompareTo longValue}" + printfn $"Comparing {bigIntValue} with {ulongValue}: {bigIntValue.CompareTo ulongValue}" + // The example displays the following output: + // Comparing 3221123045552 with 16: 1 + // Comparing 3221123045552 with -16: 1 + // Comparing 3221123045552 with 1233: 1 + // Comparing 3221123045552 with 1233: 1 + // Comparing 3221123045552 with -12233: 1 + // Comparing 3221123045552 with 12233: 1 + // Comparing 3221123045552 with 12382222: 1 + // Comparing 3221123045552 with 1238222: 1 + // + +let compareToObject () = + // + let values = + [| BigInteger.Pow(Int64.MaxValue, 10) + Unchecked.defaultof + bigint 12.534 + Int64.MaxValue + BigInteger.One |] + + let number = bigint UInt64.MaxValue + + for value in values do + try + printfn $"Comparing {number} with '{value}': {number.CompareTo value}" + with :? ArgumentException as e -> + printfn $"Unable to compare the {value.GetType().Name} value {value} with a BigInteger." + // The example displays the following output: + // Comparing 18446744073709551615 with '4.4555084156466750133735972424E+189': -1 + // Comparing 18446744073709551615 with '': 1 + // Unable to compare the Double value 12.534 with a BigInteger. + // Unable to compare the Int64 value 9223372036854775807 with a BigInteger. + // Comparing 18446744073709551615 with '1': 1 + // +compareToLong () +compareToObject () diff --git a/snippets/fsharp/System.Numerics/BigInteger/CompareTo/fs.fsproj b/snippets/fsharp/System.Numerics/BigInteger/CompareTo/fs.fsproj new file mode 100644 index 00000000000..b0739e97749 --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/CompareTo/fs.fsproj @@ -0,0 +1,11 @@ + + + Exe + net8.0 + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/BigInteger/Divide/Divide1.fs b/snippets/fsharp/System.Numerics/BigInteger/Divide/Divide1.fs new file mode 100644 index 00000000000..01a14acf494 --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/Divide/Divide1.fs @@ -0,0 +1,62 @@ +// +open System +open System.Numerics + +let divisor = BigInteger.Pow(Int64.MaxValue, 2) + +let dividends = + [| BigInteger.Multiply(bigint Single.MaxValue, 2) + BigInteger.Parse "90612345123875509091827560007100099" + BigInteger.One + BigInteger.Multiply(Int32.MaxValue, Int64.MaxValue) + divisor + BigInteger.One |] + +// Divide each dividend by divisor in three different ways. +for dividend in dividends do + let mutable quotient = 0I + let mutable remainder = 0I + + printfn $"Dividend: {dividend:N0}" + printfn $"Divisor: {divisor:N0}" + printfn "Results:" + printfn $" Using Divide method: {BigInteger.Divide(dividend, divisor):N0}" + printfn $" Using Division operator: {dividend / divisor:N0}" + quotient <- BigInteger.DivRem(dividend, divisor, &remainder) + printfn $" Using DivRem method: {quotient:N0}, remainder {remainder:N0}" + printfn "" +// The example displays the following output: +// Dividend: 680,564,693,277,057,719,623,408,366,969,033,850,880 +// Divisor: 85,070,591,730,234,615,847,396,907,784,232,501,249 +// Results: +// Using Divide method: 7 +// Using Division operator: 7 +// Using DivRem method: 7, remainder 85,070,551,165,415,408,691,630,012,479,406,342,137 +// +// Dividend: 90,612,345,123,875,509,091,827,560,007,100,099 +// Divisor: 85,070,591,730,234,615,847,396,907,784,232,501,249 +// Results: +// Using Divide method: 0 +// Using Division operator: 0 +// Using DivRem method: 0, remainder 90,612,345,123,875,509,091,827,560,007,100,099 +// +// Dividend: 1 +// Divisor: 85,070,591,730,234,615,847,396,907,784,232,501,249 +// Results: +// Using Divide method: 0 +// Using Division operator: 0 +// Using DivRem method: 0, remainder 1 +// +// Dividend: 19,807,040,619,342,712,359,383,728,129 +// Divisor: 85,070,591,730,234,615,847,396,907,784,232,501,249 +// Results: +// Using Divide method: 0 +// Using Division operator: 0 +// Using DivRem method: 0, remainder 19,807,040,619,342,712,359,383,728,129 +// +// Dividend: 85,070,591,730,234,615,847,396,907,784,232,501,250 +// Divisor: 85,070,591,730,234,615,847,396,907,784,232,501,249 +// Results: +// Using Divide method: 1 +// Using Division operator: 1 +// Using DivRem method: 1, remainder 1 +// diff --git a/snippets/fsharp/System.Numerics/BigInteger/Divide/fs.fsproj b/snippets/fsharp/System.Numerics/BigInteger/Divide/fs.fsproj new file mode 100644 index 00000000000..52a8d941554 --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/Divide/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/BigInteger/Equals/EqualsExample1.fs b/snippets/fsharp/System.Numerics/BigInteger/Equals/EqualsExample1.fs new file mode 100644 index 00000000000..4dcf2dcc5b6 --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/Equals/EqualsExample1.fs @@ -0,0 +1,85 @@ +module equalsExample1 + +open System +open System.Numerics + +let equalsLong () = + // + let byteValue = 16uy + let bigIntValue = BigInteger byteValue + + printfn + $"{bigIntValue.GetType().Name} {bigIntValue} = {byteValue.GetType().Name} {byteValue} : {bigIntValue.Equals(byteValue)}" + + let sbyteValue = -16y + let bigIntValue = BigInteger sbyteValue + + printfn + $"{bigIntValue.GetType().Name} {bigIntValue} = {sbyteValue.GetType().Name} {sbyteValue} : {bigIntValue.Equals(sbyteValue)}" + + let shortValue = 1233s + let bigIntValue = BigInteger shortValue + + printfn + $"{bigIntValue.GetType().Name} {bigIntValue} = {shortValue.GetType().Name} {shortValue} : {bigIntValue.Equals(shortValue)}" + + let ushortValue = 64000us + let bigIntValue = BigInteger ushortValue + + printfn + $"{bigIntValue.GetType().Name} {bigIntValue} = {ushortValue.GetType().Name} {ushortValue} : {bigIntValue.Equals(ushortValue)}" + + let intValue = -1603854 + let bigIntValue = BigInteger intValue + + printfn + $"{bigIntValue.GetType().Name} {bigIntValue} = {intValue.GetType().Name} {intValue} : {bigIntValue.Equals(intValue)}" + + let uintValue = 1223300u + let bigIntValue = BigInteger uintValue + + printfn + $"{bigIntValue.GetType().Name} {bigIntValue} = {uintValue.GetType().Name} {uintValue} : {bigIntValue.Equals(uintValue)}" + + let longValue = -123822229012L + let bigIntValue = BigInteger longValue + + printfn + $"{bigIntValue.GetType().Name} {bigIntValue} = {longValue.GetType().Name} {longValue} : {bigIntValue.Equals(longValue)}" + // The example displays the following output: + // BigInteger 16 = Byte 16 : True + // BigInteger -16 = SByte -16 : True + // BigInteger 1233 = Int16 1233 : True + // BigInteger 64000 = UInt16 64000 : True + // BigInteger -1603854 = Int32 -1603854 : True + // BigInteger 1223300 = UInt32 1223300 : True + // BigInteger -123822229012 = Int64 -123822229012 : True + // + +let equalsBigInteger () = + // + let LIGHT_YEAR = 5878625373183L + + let altairDistance = 17I * bigint LIGHT_YEAR + let epsilonIndiDistance = 12I * bigint LIGHT_YEAR + let ursaeMajoris47Distance = 46I * bigint LIGHT_YEAR + let tauCetiDistance = 12L * LIGHT_YEAR + let procyon2Distance = 12uL * uint64 LIGHT_YEAR + let wolf424ABDistance = 14L * LIGHT_YEAR + + printfn "Approx. equal distances from Epsilon Indi to:" + printfn $" Altair: {epsilonIndiDistance.Equals(altairDistance)}" + printfn $" Ursae Majoris 47: {epsilonIndiDistance.Equals(ursaeMajoris47Distance)}" + printfn $" TauCeti: {epsilonIndiDistance.Equals(tauCetiDistance)}" + printfn $" Procyon 2: {epsilonIndiDistance.Equals(procyon2Distance)}" + printfn $" Wolf 424 AB: {epsilonIndiDistance.Equals(wolf424ABDistance)}" + // The example displays the following output: + // Approx. equal distances from Epsilon Indi to: + // Altair: False + // Ursae Majoris 47: False + // TauCeti: True + // Procyon 2: True + // Wolf 424 AB: False + // +equalsLong () +equalsBigInteger () diff --git a/snippets/fsharp/System.Numerics/BigInteger/Equals/Equals_Obj1.fs b/snippets/fsharp/System.Numerics/BigInteger/Equals/Equals_Obj1.fs new file mode 100644 index 00000000000..f9fe368ef50 --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/Equals/Equals_Obj1.fs @@ -0,0 +1,23 @@ +module equalsobj + +// +open System.Numerics + +let obj: obj[] = [| 0; 10; 100; BigInteger 1000; -10 |] + +let bi = + [| BigInteger.Zero + BigInteger 10 + BigInteger 100 + BigInteger 1000 + BigInteger -10 |] + +for ctr = 0 to bi.Length - 1 do + printfn $"{bi.[ctr].Equals(obj.[ctr])}" +// The example displays the following output: +// False +// False +// False +// True +// False +// diff --git a/snippets/fsharp/System.Numerics/BigInteger/Equals/fs.fsproj b/snippets/fsharp/System.Numerics/BigInteger/Equals/fs.fsproj new file mode 100644 index 00000000000..13486c96b7a --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/Equals/fs.fsproj @@ -0,0 +1,11 @@ + + + Exe + net8.0 + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.fs b/snippets/fsharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.fs new file mode 100644 index 00000000000..ebce5676b89 --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.fs @@ -0,0 +1,340 @@ +open System +open System.Numerics + +let createBigIntegers () = + // + let bigIntFromDouble = BigInteger 179032.6541 + let bigIntFromInt64 = BigInteger 934157136952L + // + + // + let assignedFromLong: BigInteger = 6315489358112L + + let assignedFromDouble = BigInteger 179032.6541 + let assignedFromDecimal = BigInteger 64312.65m + // + + // + let fractionalNumber = 13456.92m + let wholeNumber = BigInteger fractionalNumber + printfn $"{wholeNumber}" // Displays 13456 + // + + // + // Create a BigInteger from a large double value + let impreciseNumber = -6e35 + let preciseNumber = BigInteger impreciseNumber + printfn $"{impreciseNumber:F}" + printfn $"{preciseNumber}" + let impreciseNumber = impreciseNumber + 1. + let preciseNumber = preciseNumber + 1I + let impreciseNumber = -6e35 + let preciseNumber = BigInteger impreciseNumber + // The example displays the following output to the console: + // -600000000000000000000000000000000000.00 + // -599999999999999981180196647507853312 + // -600000000000000000000000000000000000.00 + // -599999999999999981180196647507853311 + // + + // + // Create a BigInteger from a large negative float value + let negativeFloat = Single.MinValue + let negativeNumber = BigInteger negativeFloat + printfn $"{negativeFloat:F}" + printfn $"{negativeNumber}" + let negativeFloat = negativeFloat + 1f + let negativeNumber = negativeNumber + 1I + printfn $"{negativeFloat:F}" + printfn $"{negativeNumber}" + // The example displays the following output to the console: + // -340282300000000000000000000000000000000.00 + // -340282346638528859811704183484516925440 + // -340282300000000000000000000000000000000.00 + // -340282346638528859811704183484516925439 + // + +let createPositiveValueFromByteArray () = + // + let byteArray = [| 5uy; 4uy; 3uy; 2uy; 1uy |] + let newBigInt = BigInteger byteArray + printfn $"Value of newBigInt is {newBigInt} (or 0x{newBigInt:x} hex)" + // The code produces the following output: + // + // Value of newBigInt is 4328719365 (or 0x102030405 hex) + // + +let createNegativeValueFromByteArray () = + // + let byteArray = [| 5uy; 4uy; 3uy; 2uy; 1uy |] + let newBigInt = BigInteger byteArray + printfn $"Value of newBigInt is {newBigInt} (or 0x{newBigInt:x} hex)" + // + +let createThroughOperation () = + // + let longValue = 987654321L + let number = BigInteger.Pow(longValue, 3) + printfn $"{number}" // Displays 963418328693495609108518161 + // + +let callCompareTo () = + // + let bigIntegerInstance = BigInteger.Parse "3221123045552" + + let byteInteger = 16uy + let sByteInteger = -16y + let shortInteger = 1233s + let uShortInteger = 1233us + let normalInteger = -12233 + let normalUInteger = 12233u + let longInteger = 12382222L + let uLongInteger = 1238222uL + let singleValue = -123.49951F + let doubleValue = 123.49951992 + let decimalValue = 1234.556M + + printfn $"Comparison of {bigIntegerInstance} with {byteInteger}: {bigIntegerInstance.CompareTo byteInteger}" + printfn $"Comparison of {bigIntegerInstance} with {sByteInteger}: {bigIntegerInstance.CompareTo sByteInteger}" + printfn $"Comparison of {bigIntegerInstance} with {shortInteger}: {bigIntegerInstance.CompareTo shortInteger}" + printfn $"Comparison of {bigIntegerInstance} with {uShortInteger}: {bigIntegerInstance.CompareTo uShortInteger}" + printfn $"Comparison of {bigIntegerInstance} with {normalInteger}: {bigIntegerInstance.CompareTo normalInteger}" + printfn $"Comparison of {bigIntegerInstance} with {normalUInteger}: {bigIntegerInstance.CompareTo normalUInteger}" + printfn $"Comparison of {bigIntegerInstance} with {longInteger}: {bigIntegerInstance.CompareTo longInteger}" + printfn $"Comparison of {bigIntegerInstance} with {uLongInteger}: {bigIntegerInstance.CompareTo uLongInteger}" + + try + printfn $"Comparison of {bigIntegerInstance} with {singleValue}: {bigIntegerInstance.CompareTo(singleValue)}" + with :? ArgumentException -> + printfn $"Unable to compare {bigIntegerInstance} with a Single value of {singleValue}" + + try + printfn $"Comparison of {bigIntegerInstance} with {doubleValue}: {bigIntegerInstance.CompareTo(doubleValue)}" + with :? ArgumentException -> + printfn $"Unable to compare {bigIntegerInstance} with a Double value of {doubleValue}" + + try + printfn $"Comparison of {bigIntegerInstance} with {decimalValue}: {bigIntegerInstance.CompareTo(decimalValue)}" + with :? ArgumentException -> + printfn $"Unable to compare {bigIntegerInstance} with a Decimal value of {decimalValue}" + // The code produces the following output to the console: + // + // Comparison of 3221123045552 with 16: 1 + // Comparison of 3221123045552 with -16: 1 + // Comparison of 3221123045552 with 1233: 1 + // Comparison of 3221123045552 with 1233: 1 + // Comparison of 3221123045552 with -12233: 1 + // Comparison of 3221123045552 with 12233: 1 + // Comparison of 3221123045552 with 12382222: 1 + // Comparison of 3221123045552 with 1238222: 1 + // Unable to compare 3221123045552 with a Single value of -123.4995 + // Unable to compare 3221123045552 with a Double value of 123.49951992 + // Unable to compare 3221123045552 with a Decimal value of 1234.556 + // + +let multiplyIfOverflow () = + // + let number1 = 1234567890L + let number2 = 9876543210L + + try + + let product: int64 = Checked.(*) number1 number2 + () + with :? OverflowException -> + let product = BigInteger.Multiply(number1, number2) + printfn $"{product}" + // + +let compareDivisionResults (dividend: bigint) (divisor: bigint) = + // + let mutable remainder = 0I + let quotient = BigInteger.DivRem(dividend, divisor, &remainder) + printfn $"DivRem({dividend}, {divisor}) returns {quotient} with a remainder of {remainder}" + printfn $"Result of division: {BigInteger.Divide(dividend, divisor)}" + printfn $"Remainder after division: {BigInteger.Remainder(dividend, divisor)}" + // + +let GCD () = + // + let n1 = BigInteger.Pow(154382190, 3) + let n2 = BigInteger.Multiply(1643590, 166935) + + try + printfn $"The greatest common divisor of {n1} and {n2} is {BigInteger.GreatestCommonDivisor(n1, n2)}." + with :? ArgumentOutOfRangeException as e -> + printfn $"Unable to calculate the greatest common divisor:" + printfn $" {e.ActualValue} is an invalid value for {e.ParamName}" + // + +let showModPow () = + // + let number = 10I + let exponent = 3 + let modulus = 30I + printfn $"({number}^{exponent}) Mod {modulus} = {BigInteger.ModPow(number, exponent, modulus)}" // Displays 10 + // + +let showNegationMethods () = + // + let number = 12645002I + + printfn $"{BigInteger.Negate number}" // Displays -12645002 + printfn $"{-number}" // Displays -12645002 + printfn $"{number * BigInteger.MinusOne}" // Displays -12645002 + // + +let multiply () = + // + let num1 = 1000456321I + let num2 = 90329434I + let result = num1 * num2 + // + () + +let add () = + // + let num1 = 1000456321I + let num2 = 90329434I + let sum = num1 + num2 + // + () + +let divide () = + // + let num1 = 100045632194I + let num2 = 90329434I + let quotient = num1 / num2 + // + () + +let subtract () = + // + let num1 = 100045632194I + let num2 = 90329434I + let result = num1 - num2 + // + () + +let decrement () = + // + let mutable number = 93843112I + number <- number - 1I + printfn $"{number}" // Displays 93843111 + // + +let equality () = + // + let number1 = 945834723I + let number2 = 345145625I + let number3 = 945834723I + printfn $"{number1 = number2}" // Displays False + printfn $"{number1 = number3}" // Displays True + // + +let greaterThan () = + // + let number1 = 945834723I + let number2 = 345145625I + let number3 = 945834724I + printfn $"{number1 > number2}" // Displays True + printfn $"{number1 > number3}" // Displays False + // + +let greaterThanOrEqualTo () = + // + let number1 = 945834723I + let number2 = 345145625I + let number3 = 945834724I + let number4 = 945834723I + printfn $"{number1 >= number2}" // Displays True + printfn $"{number1 >= number3}" // Displays False + printfn $"{number1 >= number4}" // Displays True + // + +let increment () = + // + let mutable number = 93843112I + number <- number + 1I + printfn $"{number}" // Displays 93843113 + // + +let inequality () = + // + let number1 = 945834723I + let number2 = 345145625I + let number3 = 945834723I + printfn $"{number1 <> number2}" // Displays True + printfn $"{number1 <> number3}" // Displays False + // + +let lessThan () = + // + let number1 = 945834723I + let number2 = 345145625I + let number3 = 945834724I + printfn $"{number1 < number2}" // Displays False + printfn $"{number1 < number3}" // Displays True + // + +let lessThanOrEqualTo () = + // + let number1 = 945834723I + let number2 = 345145625I + let number3 = 945834724I + let number4 = 945834723I + printfn $"{number1 <= number2}" // Displays False + printfn $"{number1 <= number3}" // Displays True + printfn $"{number1 <= number4}" // Displays True + // + +let modulus () = + // + let num1 = 100045632194I + let num2 = 90329434I + let remainder = num1 % num2 + printfn $"{remainder}" // Displays 50948756 + // + +let showExponentiation () = + // + let numericBase = 3040506I + + for ctr in 0..10 do + printfn $"{BigInteger.Pow(numericBase, ctr)}" + // + // The example produces the following output to the console: + // + // 1 + // 3040506 + // 9244676736036 + // 28108495083977874216 + // 85464047953805230420993296 + // 259853950587832525926412642447776 + // 790087495886008322074413197838317614656 + // 2402265771766383619317185774506591737267255936 + // 7304103492650319992835619250501939216711515276943616 + // 22208170494024253840136657344866649200046662468638726109696 + // 67524075636103707946458547477011116092637077515870858568887346176 + // + +// +type StarDistances() = + [] + let LIGHT_YEAR = 5878625373183L + + member _.CompareStarDistances() = + let altairDistance = 17I * bigint LIGHT_YEAR + let epsilonIndiDistance = 12I * bigint LIGHT_YEAR + let ursaeMajoris47Distance = 46I * bigint LIGHT_YEAR + let tauCetiDistance = 12I * bigint LIGHT_YEAR + let procyon2Distance: int64 = 12L * LIGHT_YEAR + let wolf424ABDistance = int64 14 * LIGHT_YEAR + + printfn "Approx. equal distances from Epsilon Indi to:" + printfn $" Altair: {epsilonIndiDistance.Equals altairDistance}" + printfn $" Ursae Majoris 47: {epsilonIndiDistance.Equals ursaeMajoris47Distance}" + printfn $" TauCeti: {epsilonIndiDistance.Equals tauCetiDistance}" + printfn $" Procyon 2: {epsilonIndiDistance.Equals procyon2Distance}" + printfn $" Wolf 424 AB: {epsilonIndiDistance.Equals wolf424ABDistance}" +// diff --git a/snippets/fsharp/System.Numerics/BigInteger/GreatestCommonDivisor/fs.fsproj b/snippets/fsharp/System.Numerics/BigInteger/GreatestCommonDivisor/fs.fsproj new file mode 100644 index 00000000000..50ea3eaab1e --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/GreatestCommonDivisor/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/BigInteger/LogMethod/fs.fsproj b/snippets/fsharp/System.Numerics/BigInteger/LogMethod/fs.fsproj new file mode 100644 index 00000000000..7089d0d7333 --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/LogMethod/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/BigInteger/LogMethod/log1.fs b/snippets/fsharp/System.Numerics/BigInteger/LogMethod/log1.fs new file mode 100644 index 00000000000..6b54a64bca3 --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/LogMethod/log1.fs @@ -0,0 +1,18 @@ +// +open System +open System.Numerics + +let values = [| 2I; 100I; BigInteger.Pow(1000I, 100); BigInteger.Pow(2I, 64) |] + +for value in values do + printfn $"The square root of {value} is {Math.Exp(BigInteger.Log(value) / 2.)}" +// The example displays the following output: +// The square root of 2 is 1.41421356237309 +// The square root of 100 is 10 +// The square root of 1000000000000000000000000000000000000000000000000000000000000 +// 00000000000000000000000000000000000000000000000000000000000000000000000000000000 +// 00000000000000000000000000000000000000000000000000000000000000000000000000000000 +// 00000000000000000000000000000000000000000000000000000000000000000000000000000000 +// is 9.99999999999988E+149 +// The square root of 18446744073709551616 is 4294967296 +// diff --git a/snippets/fsharp/System.Numerics/BigInteger/Max/Max1.fs b/snippets/fsharp/System.Numerics/BigInteger/Max/Max1.fs new file mode 100644 index 00000000000..119f41c93c8 --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/Max/Max1.fs @@ -0,0 +1,39 @@ +// +open System +open System.Numerics + +let numbers = + [| bigint Int64.MaxValue * BigInteger.MinusOne + BigInteger.MinusOne + 10359321239000I + BigInteger.Pow(103988I, 2) + BigInteger.Multiply(Int32.MaxValue, Int16.MaxValue) + BigInteger.Add(BigInteger.Pow(Int64.MaxValue, 2), BigInteger.Pow(Int32.MaxValue, 2)) |] + +if numbers.Length < 2 then + printfn $"Cannot determine which is the larger of {numbers.Length} numbers." +else + let mutable largest = numbers[0] + + for ctr = 1 to numbers.Length - 1 do + largest <- BigInteger.Max(largest, numbers[ctr]) + + printfn "The values:" + + for number in numbers do + printfn $"{number, 55:N0}" + + printfn "\nThe largest number of the series is:" + printfn $" {largest:N0}" +// The example displays the following output: +// The values: +// -9,223,372,036,854,775,807 +// -1 +// 10,359,321,239,000 +// 10,813,504,144 +// 70,366,596,661,249 +// 85,070,591,730,234,615,852,008,593,798,364,921,858 +// +// The largest number of the series is: +// 85,070,591,730,234,615,852,008,593,798,364,921,858 +// diff --git a/snippets/fsharp/System.Numerics/BigInteger/Max/fs.fsproj b/snippets/fsharp/System.Numerics/BigInteger/Max/fs.fsproj new file mode 100644 index 00000000000..4605b7949cb --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/Max/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/BigInteger/Min/Min1.fs b/snippets/fsharp/System.Numerics/BigInteger/Min/Min1.fs new file mode 100644 index 00000000000..2ed099aa79e --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/Min/Min1.fs @@ -0,0 +1,41 @@ +// +open System +open System.Numerics + +let numbers = + [| bigint Int64.MaxValue * BigInteger.MinusOne + BigInteger.MinusOne + 10359321239000I + BigInteger.Pow(103988I, 2) + BigInteger.Multiply(Int32.MaxValue, Int16.MaxValue) + BigInteger.Add(BigInteger.Pow(Int64.MaxValue, 2), BigInteger.Pow(Int32.MaxValue, 2)) + BigInteger.Zero |] + +if numbers.Length < 2 then + printfn $"Cannot determine which is the smaller of {numbers.Length} numbers." +else + let mutable smallest = numbers[0] + + for ctr = 1 to numbers.Length - 1 do + smallest <- BigInteger.Min(smallest, numbers[ctr]) + + printfn "The values:" + + for number in numbers do + printfn $"{number, 55:N0}" + + printfn "\nThe smallest number of the series is:" + printfn $" {smallest:N0}" +// The example displays the following output: +// The values: +// -9,223,372,036,854,775,807 +// -1 +// 10,359,321,239,000 +// 10,813,504,144 +// 70,366,596,661,249 +// 85,070,591,730,234,615,852,008,593,798,364,921,858 +// 0 +// +// The smallest number of the series is: +// -9,223,372,036,854,775,807. +// diff --git a/snippets/fsharp/System.Numerics/BigInteger/Min/fs.fsproj b/snippets/fsharp/System.Numerics/BigInteger/Min/fs.fsproj new file mode 100644 index 00000000000..f98aacb683c --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/Min/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/BigInteger/ModPow/ModPow1.fs b/snippets/fsharp/System.Numerics/BigInteger/ModPow/ModPow1.fs new file mode 100644 index 00000000000..629699c1723 --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/ModPow/ModPow1.fs @@ -0,0 +1,10 @@ +// +open System.Numerics; + +let number = 10I; +let exponent = 3; +let modulus = 30I; +printfn $"({number}^{exponent}) Mod {modulus} = {BigInteger.ModPow(number, exponent, modulus)}" +// The example displays the following output: +// (10^3) Mod 30 = 10 +// \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/BigInteger/ModPow/fs.fsproj b/snippets/fsharp/System.Numerics/BigInteger/ModPow/fs.fsproj new file mode 100644 index 00000000000..c3fa828cc63 --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/ModPow/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/BigInteger/Parse/Parse1.fs b/snippets/fsharp/System.Numerics/BigInteger/Parse/Parse1.fs new file mode 100644 index 00000000000..8c4e123bc0c --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/Parse/Parse1.fs @@ -0,0 +1,100 @@ +module parse1 + +open System +open System.Globalization +open System.Numerics + +let parseString () = + // + let mutable stringToParse = "" + + try + // Parse two strings. + let string1 = "12347534159895123" + let string2 = "987654321357159852" + stringToParse <- string1 + let number1 = BigInteger.Parse stringToParse + printfn $"Converted '{stringToParse}' to {number1:N0}." + stringToParse <- string2 + let number2 = BigInteger.Parse stringToParse + printfn $"Converted '{stringToParse}' to {number2:N0}." + // Perform arithmetic operations on the two numbers. + let number1 = number1 * bigint 3 + let number2 = number2 * bigint 2 + // Compare the numbers. + let result = BigInteger.Compare(number1, number2) + + match result with + | -1 -> printfn $"{number2:N0} is greater than {number1:N0}." + | 0 -> printfn $"{number1:N0} is equal to {number2:N0}." + | 1 + | _ -> printfn $"{number1:N0} is greater than {number2:N0}." + with :? FormatException -> + printfn $"Unable to parse {stringToParse}." + +// The example displays the following output: +// Converted '12347534159895123' to 12,347,534,159,895,123. +// Converted '987654321357159852' to 987,654,321,357,159,852. +// 1975308642714319704 is greater than 37042602479685369. +// + +// +type BigIntegerFormatProvider() = + interface IFormatProvider with + + member _.GetFormat(formatType: Type) = + if formatType = typeof then + let numberFormat = NumberFormatInfo() + numberFormat.NegativeSign <- "~" + numberFormat + else + null +// + + +let parseWithStyleAndProvider () = + // + // Call parse with default values of style and provider + printfn $"""{BigInteger.Parse(" -300 ", NumberStyles.Integer, CultureInfo.CurrentCulture)}""" + + // Call parse with default values of style and provider supporting tilde as negative sign + printfn $"""{BigInteger.Parse(" ~300 ", NumberStyles.Integer, new BigIntegerFormatProvider())}""" + + // Call parse with only AllowLeadingWhite and AllowTrailingWhite + // Exception thrown because of presence of negative sign + try + printfn + $"""{BigInteger.Parse( + " ~300 ", + NumberStyles.AllowLeadingWhite ||| NumberStyles.AllowTrailingWhite, + new BigIntegerFormatProvider() + )}""" + with :? FormatException as e -> + printfn $"{e.GetType().Name}: \n {e.Message}" + + // Call parse with only AllowHexSpecifier + // Exception thrown because of presence of negative sign + try + printfn $"""{BigInteger.Parse("-3af", NumberStyles.AllowHexSpecifier, new BigIntegerFormatProvider())}""" + with :? FormatException as e -> + printfn $"{e.GetType().Name}: \n {e.Message}" + + // Call parse with only NumberStyles.None + // Exception thrown because of presence of white space and sign + try + printfn $"""{BigInteger.Parse(" -300 ", NumberStyles.None, new BigIntegerFormatProvider())}""" + with :? FormatException as e -> + printfn $"{e.GetType().Name}: \n {e.Message}" +// The example displays the followingoutput: +// -300 +// -300 +// FormatException: +// The value could not be parsed. +// FormatException: +// The value could not be parsed. +// FormatException: +// The value could not be parsed. +// + +parseString () +parseWithStyleAndProvider () diff --git a/snippets/fsharp/System.Numerics/BigInteger/Parse/ParseHex1.fs b/snippets/fsharp/System.Numerics/BigInteger/Parse/ParseHex1.fs new file mode 100644 index 00000000000..2217e2ee6f3 --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/Parse/ParseHex1.fs @@ -0,0 +1,37 @@ +module parsehex + +// +open System.Globalization +open System.Numerics + +let hexStrings = + [| "80" + "E293" + "F9A2FF" + "FFFFFFFF" + "080" + "0E293" + "0F9A2FF" + "0FFFFFFFF" + "0080" + "00E293" + "00F9A2FF" + "00FFFFFFFF" |] + +for hexString in hexStrings do + let number = BigInteger.Parse(hexString, NumberStyles.AllowHexSpecifier) + printfn $"Converted 0x{hexString} to {number:N0}." +// The example displays the following output: +// Converted 0x80 to -128. +// Converted 0xE293 to -7533. +// Converted 0xF9A2FF to -417025. +// Converted 0xFFFFFFFF to -1. +// Converted 0x080 to 128. +// Converted 0x0E293 to 58003. +// Converted 0x0F9A2FF to 16360191. +// Converted 0x0FFFFFFFF to 4294967295. +// Converted 0x0080 to 128. +// Converted 0x00E293 to 58003. +// Converted 0x00F9A2FF to 16360191. +// Converted 0x00FFFFFFFF to 4294967295. +// diff --git a/snippets/fsharp/System.Numerics/BigInteger/Parse/System.Numeric.BigInteger.Parse.fs b/snippets/fsharp/System.Numerics/BigInteger/Parse/System.Numeric.BigInteger.Parse.fs new file mode 100644 index 00000000000..80adda58b98 --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/Parse/System.Numeric.BigInteger.Parse.fs @@ -0,0 +1,130 @@ +module parse + +open System +open System.Globalization +open System.Numerics + + +// +type BigIntegerFormatProvider() = + interface IFormatProvider with + + member _.GetFormat(formatType: Type) = + if formatType = typeof then + let numberFormat = NumberFormatInfo() + numberFormat.NegativeSign <- "~" + numberFormat + else + null +// + + +let parseString () = + // + try + // + let number1 = BigInteger.Parse "12347534159895123" + let number2 = BigInteger.Parse "987654321357159852" + // + + let number1 = number1 * bigint 3 + let number2 = number2 * bigint 2 + let result = BigInteger.Compare(number1, number2) + + match result with + | -1 -> printfn $"{number2:N0} is greater than {number1:N0}." + | 0 -> printfn $"{number1:N0} is equal to {number2:N0}." + | 1 + | _ -> printfn $"{number1:N0} is greater than {number2:N0}." + with :? FormatException -> + printfn $"Unable to initialize integer because of invalid format in string." + +// + +let parseStringWithIFormatProvider () = + // + let fmt = NumberFormatInfo() + fmt.NegativeSign <- "~" + + let number = BigInteger.Parse("~6354129876", fmt) + printfn $"{number.ToString fmt}" + printfn $"{number}" +// + +let parseWithCustomIFormatProvider () = + // + let number = BigInteger.Parse("~6354129876", BigIntegerFormatProvider()) + printfn $"{number.ToString(BigIntegerFormatProvider())}" + printfn $"{number}" +// + +let parseWithStyle () = + // + let number = BigInteger.Parse(" -68054 ", NumberStyles.Integer) + printfn $"{number}" + let number = BigInteger.Parse("68054", NumberStyles.AllowHexSpecifier) + printfn $"{number}" + + try + let number = + BigInteger.Parse(" -68054 ", NumberStyles.AllowLeadingWhite ||| NumberStyles.AllowTrailingWhite) + + printfn $"{number}" + with :? FormatException as e -> + printfn $"{e.Message}" + + try + let number = BigInteger.Parse(" 68054 ", NumberStyles.AllowLeadingSign) + printfn $"{number}" + with :? FormatException as e -> + printfn $"{e.Message}" +// The method produces the following output: +// -68054 +// 426068 +// Input string was not in a correct format. +// Input string was not in a correct format. +// + +let parseOverload4 () = + // + // Call parse with default values of style and provider + printfn $"""{BigInteger.Parse(" -300 ", NumberStyles.Integer, CultureInfo.CurrentCulture)}""" + + // Call parse with default values of style and provider supporting tilde as negative sign + printfn $"""{BigInteger.Parse(" ~300 ", NumberStyles.Integer, BigIntegerFormatProvider())}""" + + // Call parse with only AllowLeadingWhite and AllowTrailingWhite + // Exception thrown because of presence of negative sign + try + printfn + $"""{BigInteger.Parse( + " ~300 ", + NumberStyles.AllowLeadingWhite ||| NumberStyles.AllowTrailingWhite, + BigIntegerFormatProvider() + )}""" + with :? FormatException as e -> + printfn $"{e.GetType().Name}: \n {e.Message}" + + // Call parse with only AllowHexSpecifier + // Exception thrown because of presence of negative sign + try + printfn $"""{BigInteger.Parse("-3af", NumberStyles.AllowHexSpecifier, BigIntegerFormatProvider())}""" + with :? FormatException as e -> + printfn $"{e.GetType().Name}: \n {e.Message}" + + // Call parse with only NumberStyles.None + // Exception thrown because of presence of white space and sign + try + printfn $"""{BigInteger.Parse(" -300 ", NumberStyles.None, BigIntegerFormatProvider())}""" + with :? FormatException as e -> + printfn $"{e.GetType().Name}: \n {e.Message}" +// < + +parseString () +Console.WriteLine() +parseStringWithIFormatProvider () +Console.WriteLine() +parseWithCustomIFormatProvider () +Console.WriteLine() +parseWithStyle () +parseOverload4 () diff --git a/snippets/fsharp/System.Numerics/BigInteger/Parse/fs.fsproj b/snippets/fsharp/System.Numerics/BigInteger/Parse/fs.fsproj new file mode 100644 index 00000000000..1c86048c6c9 --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/Parse/fs.fsproj @@ -0,0 +1,12 @@ + + + Exe + net8.0 + + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/BigInteger/Remainder/Remainder1.fs b/snippets/fsharp/System.Numerics/BigInteger/Remainder/Remainder1.fs new file mode 100644 index 00000000000..682568688ee --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/Remainder/Remainder1.fs @@ -0,0 +1,42 @@ +// +open System +open System.Numerics + +let dividend1 = BigInteger.Pow(Int64.MaxValue, 3) +let dividend2 = dividend1 * BigInteger.MinusOne +let divisor1 = bigint Int32.MaxValue +let divisor2 = divisor1 * BigInteger.MinusOne + +let remainder1 = BigInteger.Remainder(dividend1, divisor1) +let remainder2 = BigInteger.Remainder(dividend2, divisor1) + +let mutable divRem1 = BigInteger.Zero +let mutable divRem2 = BigInteger.Zero + +BigInteger.DivRem(dividend1, divisor1, &divRem1) |> ignore + +printfn $"BigInteger.Remainder({dividend1}, {divisor1}) = {remainder1}" + +printfn $"BigInteger.DivRem({dividend1}, {divisor1}) = {divRem1}" + + +if remainder1.Equals divRem1 then + printfn $"The remainders are equal.\n" + +BigInteger.DivRem(dividend2, divisor2, &divRem2) |> ignore + +printfn $"BigInteger.Remainder({dividend2}, {divisor2}) = {remainder2}" +printfn $"BigInteger.DivRem({dividend2}, {divisor2}) = {divRem2}" + +if remainder2.Equals divRem2 then + printfn $"The remainders are equal.\n" + +// The example displays the following output: +// BigInteger.Remainder(784637716923335095224261902710254454442933591094742482943, 2147483647) = 1 +// BigInteger.DivRem(784637716923335095224261902710254454442933591094742482943, 2147483647) = 1 +// The remainders are equal. +// +// BigInteger.Remainder(-784637716923335095224261902710254454442933591094742482943, -2147483647) = -1 +// BigInteger.DivRem(-784637716923335095224261902710254454442933591094742482943, -2147483647) = -1 +// The remainders are equal. +// diff --git a/snippets/fsharp/System.Numerics/BigInteger/Remainder/fs.fsproj b/snippets/fsharp/System.Numerics/BigInteger/Remainder/fs.fsproj new file mode 100644 index 00000000000..f8c5555e29e --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/Remainder/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/BigInteger/ToByteArray/ToByteArray1.fs b/snippets/fsharp/System.Numerics/BigInteger/ToByteArray/ToByteArray1.fs new file mode 100644 index 00000000000..28b6787c533 --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/ToByteArray/ToByteArray1.fs @@ -0,0 +1,38 @@ +// +open System +open System.Numerics + +let numbers = + [| BigInteger.MinusOne + BigInteger.One + BigInteger.Zero + 120 + 128 + 255 + 1024 + Int64.MinValue + Int64.MaxValue + BigInteger.Parse("90123123981293054321") |] + +for number in numbers do + let bytes = number.ToByteArray() + printf $"""{number} ({number.ToString("X" + (bytes.Length * 2).ToString())}) -> """ + printf $"{bytes.Length} bytes: " + + for byteValue in bytes do + printf $"{byteValue:X2} " + + printfn "" + +// The example displays the following output: +// -1 (FF) -> 1 bytes: FF +// 1 (01) -> 1 bytes: 01 +// 0 (00) -> 1 bytes: 00 +// 120 (78) -> 1 bytes: 78 +// 128 (0080) -> 2 bytes: 80 00 +// 255 (00FF) -> 2 bytes: FF 00 +// 1024 (0400) -> 2 bytes: 00 04 +// -9223372036854775808 (8000000000000000) -> 8 bytes: 00 00 00 00 00 00 00 80 +// 9223372036854775807 (7FFFFFFFFFFFFFFF) -> 8 bytes: FF FF FF FF FF FF FF 7F +// 90123123981293054321 (04E2B5A7C4A975E971) -> 9 bytes: 71 E9 75 A9 C4 A7 B5 E2 04 +// diff --git a/snippets/fsharp/System.Numerics/BigInteger/ToByteArray/fs.fsproj b/snippets/fsharp/System.Numerics/BigInteger/ToByteArray/fs.fsproj new file mode 100644 index 00000000000..07467fafcd9 --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/ToByteArray/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/BigInteger/ToString/System.Numeric.BigInteger.ToString.fs b/snippets/fsharp/System.Numerics/BigInteger/ToString/System.Numeric.BigInteger.ToString.fs new file mode 100644 index 00000000000..c3ce02c4e3b --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/ToString/System.Numeric.BigInteger.ToString.fs @@ -0,0 +1,42 @@ +module tostring + +open System.Globalization +open System.Numerics + + +let callToString1 () = + // + let number = bigint 9867857831128L + let number = BigInteger.Pow(number, 3) * BigInteger.MinusOne + + let bigIntegerProvider = NumberFormatInfo() + bigIntegerProvider.NegativeSign <- "~" + + printfn $"{number.ToString(bigIntegerProvider)}" +// + + +let callToString2 () = + // + let number = bigint 9867857831128L + printfn $"""{number.ToString("G")}""" + printfn $"""{number.ToString("D")}""" + printfn $"""{number.ToString("X")}""" +// + +let callToString3 () = + // + let bigIntegerFormat = NumberFormatInfo() + bigIntegerFormat.NegativeSign <- "~" + + let number = BigInteger.MinusOne * bigint 9867857831128L + + printfn $"""{number.ToString("G")}""" + printfn $"""{number.ToString("D")}""" + printfn $"""{number.ToString("X")}""" +// + + +callToString1 () +callToString2 () +callToString3 () diff --git a/snippets/fsharp/System.Numerics/BigInteger/ToString/ToString1.fs b/snippets/fsharp/System.Numerics/BigInteger/ToString/ToString1.fs new file mode 100644 index 00000000000..77d7f24ac8f --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/ToString/ToString1.fs @@ -0,0 +1,163 @@ +module tostring1 + +open System +open System.Globalization +open System.Numerics + +let toStringDft () = + // + // Initialize a BigInteger value. + let value = BigInteger.Add(UInt64.MaxValue, 1024) + + // Display value using the default ToString method. + printfn $"{value.ToString()}" + // Display value using some standard format specifiers. + printfn $"""{value.ToString("G")}""" + printfn $"""{value.ToString("C")}""" + printfn $"""{value.ToString("D")}""" + printfn $"""{value.ToString("F")}""" + printfn $"""{value.ToString("N")}""" + printfn $"""{value.ToString("X")}""" +// The example displays the following output on a system whose current +// culture is en-US: +// 18446744073709552639 +// 18446744073709552639 +// $18,446,744,073,709,552,639.00 +// 18446744073709552639 +// 18446744073709552639.00 +// 18,446,744,073,709,552,639.00 +// 100000000000003FF +// + + +let roundtripValue () = + // + // Create number with 50+ digits and store it to two strings. + let originalNumber = BigInteger.Pow(UInt64.MaxValue, int Byte.MaxValue) + let generalString = originalNumber.ToString "G" + let roundTripString = originalNumber.ToString "R" + + printfn + $"""The original value has {originalNumber.ToString("X").Length} hexadecimal digits. +""" + + // Attempt to round-trip strings and compare them with the original. + printfn "Parsing the string formatted with the 'G' format string." + + let generalBigInteger = + BigInteger.Parse(generalString, NumberStyles.AllowExponent ||| NumberStyles.AllowDecimalPoint) + + if originalNumber.Equals(generalBigInteger) then + printfn "The values are equal. No data has been lost." + else + printfn "The values are not equal. Data has been lost." + + printfn "Parsing the string formatted with the 'R' format string." + let roundTripBigInteger = BigInteger.Parse roundTripString + + if originalNumber.Equals roundTripBigInteger then + printfn "The values are equal. No data has been lost." + else + printfn "The values are not equal. Data has been lost." +// The example displays the following output: +// The original value has 4080 hexadecimal digits. +// +// Parsing the string formatted with the 'G' format string. +// The values are not equal. Data has been lost. +// +// Parsing the string formatted with the 'R' format string. +// The values are equal. No data has been lost. +// + + +let toFormattedString () = + // + // Define a BigInteger value. + let value = BigInteger.Parse "-903145792771643190182" + + let specifiers = + [| "C" + "D" + "D25" + "E" + "E4" + "e8" + "F0" + "G" + "N0" + "P" + "R" + "X" + "0,0.000" + "#,#.00#;(#,#.00#)" |] + + for specifier in specifiers do + printfn $"{specifier}: {value.ToString specifier}" +// The example displays the following output: +// C: ($903,145,792,771,643,190,182.00) +// D: -903145792771643190182 +// D25: -0000903145792771643190182 +// E: -9.031457E+020 +// E4: -9.0314E+020 +// e8: -9.03145792e+020 +// F0: -903145792771643190182 +// G: -903145792771643190182 +// N0: -903,145,792,771,643,190,182 +// P: -90,314,579,277,164,319,018,200.00 % +// R: -903145792771643190182 +// X: CF0A55968BB1A7545A +// 0,0.000: -903,145,792,771,643,190,182.000 +// #,#.00#;(#,#.00#): (903,145,792,771,643,190,182.00) +// + +let FormatStringWithProvider () = + // + // Redefine the negative sign as the tilde for the invariant culture. + let bigIntegerFormatter = NumberFormatInfo() + bigIntegerFormatter.NegativeSign <- "~" + + let value = BigInteger.Parse "-903145792771643190182" + + let specifiers = + [| "C" + "D" + "D25" + "E" + "E4" + "e8" + "F0" + "G" + "N0" + "P" + "R" + "X" + "0,0.000" + "#,#.00#;(#,#.00#)" |] + + for specifier in specifiers do + printfn $"{specifier}: {value.ToString(specifier, bigIntegerFormatter)}" + +// The example displays the following output: +// C: (☼903,145,792,771,643,190,182.00) +// D: ~903145792771643190182 +// D25: ~0000903145792771643190182 +// E: ~9.031457E+020 +// E4: ~9.0314E+020 +// e8: ~9.03145792e+020 +// F0: ~903145792771643190182 +// G: ~903145792771643190182 +// N0: ~903,145,792,771,643,190,182 +// P: ~90,314,579,277,164,319,018,200.00 % +// R: ~903145792771643190182 +// X: CF0A55968BB1A7545A +// 0,0.000: ~903,145,792,771,643,190,182.000 +// #,#.00#;(#,#.00#): (903,145,792,771,643,190,182.00) +// + +toStringDft () +printfn "-----" +roundtripValue () +printfn "-----" +toFormattedString () +printfn "-----" +FormatStringWithProvider() diff --git a/snippets/fsharp/System.Numerics/BigInteger/ToString/fs.fsproj b/snippets/fsharp/System.Numerics/BigInteger/ToString/fs.fsproj new file mode 100644 index 00000000000..710af116b06 --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/ToString/fs.fsproj @@ -0,0 +1,11 @@ + + + Exe + net8.0 + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/BigInteger/TryParse/System.Numeric.BigInteger.TryParse.fs b/snippets/fsharp/System.Numerics/BigInteger/TryParse/System.Numeric.BigInteger.TryParse.fs new file mode 100644 index 00000000000..46b40aa1f09 --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/TryParse/System.Numeric.BigInteger.TryParse.fs @@ -0,0 +1,102 @@ +module tryparse + +open System +open System.Globalization +open System.Numerics + +let tryParse1 () = + // + let mutable number1 = BigInteger.Zero + let mutable number2 = BigInteger.Zero + + let succeeded1 = BigInteger.TryParse("-12347534159895123", &number1) + let succeeded2 = BigInteger.TryParse("987654321357159852", &number2) + + if succeeded1 && succeeded2 then + number1 <- number1 * 3I + number2 <- number2 * 2I + + match BigInteger.Compare(number1, number2) with + | -1 -> printfn $"{number2} is greater than {number2}." + | 0 -> printfn $"{number1} is equal to {number2}." + | 1 + | _ -> printfn $"{number1} is greater than {number2}." + else + if not succeeded1 then + printfn "Unable to initialize the first BigInteger value." + + if not succeeded2 then + printfn "Unable to initialize the second BigInteger value." + +// The example displays the following output: +// 1975308642714319704 is greater than -37042602479685369. +// + +type BigIntegerFormatProvider() = + interface IFormatProvider with + member _.GetFormat(formatType: Type) = + if formatType = typeof then + let numberFormat = new NumberFormatInfo() + numberFormat.NegativeSign <- "~" + numberFormat + else + null + +let tryParse2 () = + // + + // Call parse with default values of style and provider + let numericString = " -300 " + + match BigInteger.TryParse(numericString, NumberStyles.Integer, CultureInfo.CurrentCulture) with + | true, number -> printfn $"The string '{numericString}' parses to {number}" + | _ -> printfn $"Conversion of {numericString} to a BigInteger failed." + + // Call parse with default values of style and provider supporting tilde as negative sign + let numericString = " -300 " + + match BigInteger.TryParse(numericString, NumberStyles.Integer, new BigIntegerFormatProvider()) with + | true, number -> printfn $"The string '{numericString}' parses to {number}" + | _ -> printfn $"Conversion of {numericString} to a BigInteger failed." + + // Call parse with only AllowLeadingWhite and AllowTrailingWhite + // Method returns false because of presence of negative sign + let numericString = " -500 " + + match + BigInteger.TryParse( + numericString, + NumberStyles.AllowLeadingWhite ||| NumberStyles.AllowTrailingWhite, + new BigIntegerFormatProvider() + ) + with + | true, number -> printfn $"The string '{numericString}' parses to {number}" + | _ -> printfn $"Conversion of {numericString} to a BigInteger failed." + + // Call parse with AllowHexSpecifier and a hex value + let numericString = "FFAAC086455192" + + match BigInteger.TryParse(numericString, NumberStyles.AllowHexSpecifier, null) with + | true, number -> printfn $"The string '{numericString}' parses to {number}, or 0x{number:x}." + | _ -> printfn $"Conversion of {numericString} to a BigInteger failed." + + // Call parse with AllowHexSpecifier and a negative hex value + // Conversion fails because of presence of negative sign + let numericString = "-3af" + + match BigInteger.TryParse(numericString, NumberStyles.AllowHexSpecifier, null) with + | true, number -> printfn $"The string '{numericString}' parses to {number}, or 0x{number:x}." + | _ -> printfn $"Conversion of {numericString} to a BigInteger failed." + + // Call parse with only NumberStyles.None + // Exception thrown because of presence of white space and sign + let numericString = " -300 " + + match BigInteger.TryParse(numericString, NumberStyles.None, new BigIntegerFormatProvider()) with + | true, number -> printfn $"The string '{numericString}' parses to {number}" + | _ -> printfn $"Conversion of {numericString} to a BigInteger failed." + +// < + +tryParse1 () +tryParse2 () diff --git a/snippets/fsharp/System.Numerics/BigInteger/TryParse/TryParse1.fs b/snippets/fsharp/System.Numerics/BigInteger/TryParse/TryParse1.fs new file mode 100644 index 00000000000..53a3313df46 --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/TryParse/TryParse1.fs @@ -0,0 +1,99 @@ +module tryparse1 + +open System +open System.Globalization +open System.Numerics + +// +type BigIntegerFormatProvider() = + interface IFormatProvider with + member _.GetFormat(formatType: Type) = + if formatType = typeof then + let numberFormat = new NumberFormatInfo() + numberFormat.NegativeSign <- "~" + numberFormat + else + null +// + +do + // + // Call TryParse with default values of style and provider. + let numericString = " -300 " + + match BigInteger.TryParse(numericString, NumberStyles.Integer, null) with + | true, number -> printfn $"The string '{numericString}' parses to {number}" + | _ -> printfn $"Conversion of {numericString} to a BigInteger failed." + + // Call TryParse with the default value of style and + // a provider supporting the tilde as negative sign. + let numericString = " -300 " + + match BigInteger.TryParse(numericString, NumberStyles.Integer, new BigIntegerFormatProvider()) with + | true, number -> printfn $"The string '{numericString}' parses to {number}" + | _ -> printfn $"Conversion of {numericString} to a BigInteger failed." + + // Call TryParse with only AllowLeadingWhite and AllowTrailingWhite. + // Method returns false because of presence of negative sign. + let numericString = " -500 " + + match + BigInteger.TryParse( + numericString, + NumberStyles.AllowLeadingWhite ||| NumberStyles.AllowTrailingWhite, + new BigIntegerFormatProvider() + ) + with + | true, number -> printfn $"The string '{numericString}' parses to {number}" + | _ -> printfn $"Conversion of {numericString} to a BigInteger failed." + + // Call TryParse with AllowHexSpecifier and a hex value. + let numericString = "F14237FFAAC086455192" + + match BigInteger.TryParse(numericString, NumberStyles.AllowHexSpecifier, null) with + | true, number -> printfn $"The string '{numericString}' parses to {number}, or 0x{number:x}." + | _ -> printfn $"Conversion of {numericString} to a BigInteger failed." + + // Call TryParse with AllowHexSpecifier and a negative hex value. + // Conversion fails because of presence of negative sign. + let numericString = "-3af" + + match BigInteger.TryParse(numericString, NumberStyles.AllowHexSpecifier, null) with + | true, number -> printfn $"The string '{numericString}' parses to {number}, or 0x{number:x}." + | _ -> printfn $"Conversion of {numericString} to a BigInteger failed." + + // Call TryParse with only NumberStyles.None. + // Conversion fails because of presence of white space and sign. + let numericString = " -300 " + + match BigInteger.TryParse(numericString, NumberStyles.None, new BigIntegerFormatProvider()) with + | true, number -> printfn $"The string '{numericString}' parses to {number}" + | _ -> printfn $"Conversion of {numericString} to a BigInteger failed." + + // Call TryParse with NumberStyles.Any and a provider for the fr-FR culture. + // Conversion fails because the string is formatted for the en-US culture. + let numericString = "9,031,425,666,123,546.00" + + match BigInteger.TryParse(numericString, NumberStyles.Any, new CultureInfo("fr-FR")) with + | true, number -> printfn $"The string '{numericString}' parses to {number}" + | _ -> printfn $"Conversion of {numericString} to a BigInteger failed." + + // Call TryParse with NumberStyles.Any and a provider for the fr-FR culture. + // Conversion succeeds because the string is properly formatted + // For the fr-FR culture. + let numericString = "9 031 425 666 123 546,00" + + match BigInteger.TryParse(numericString, NumberStyles.Any, new CultureInfo("fr-FR")) with + | true, number -> printfn $"The string '{numericString}' parses to {number}" + | _ -> printfn $"Conversion of {numericString} to a BigInteger failed." + +// The example displays the following output: +// ' -300 ' was converted to -300. +// Conversion of ' -300 ' to a BigInteger failed. +// Conversion of ' -500 ' to a BigInteger failed. +// 'F14237FFAAC086455192' was converted to -69613977002644837412462 (0xf14237ffaac086455192). +// Conversion of '-3af' to a BigInteger failed. +// Conversion of ' -300 ' to a BigInteger failed. +// Conversion of '9,031,425,666,123,546.00' to a BigInteger failed. +// '9 031 425 666 123 546,00' was converted to 9031425666123546. +// diff --git a/snippets/fsharp/System.Numerics/BigInteger/TryParse/TryParseHex1.fs b/snippets/fsharp/System.Numerics/BigInteger/TryParse/TryParseHex1.fs new file mode 100644 index 00000000000..95f511951f7 --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/TryParse/TryParseHex1.fs @@ -0,0 +1,39 @@ +module tryparsehex1 + +// +open System.Globalization +open System.Numerics + +let hexStrings = + [| "80" + "E293" + "F9A2FF" + "FFFFFFFF" + "080" + "0E293" + "0F9A2FF" + "0FFFFFFFF" + "0080" + "00E293" + "00F9A2FF" + "00FFFFFFFF" |] + +for hexString in hexStrings do + match BigInteger.TryParse(hexString, NumberStyles.AllowHexSpecifier, null) with + | true, number -> printfn $"Converted 0x{hexString} to {number}." + | _ -> printfn $"Cannot convert '{hexString}' to a BigInteger." + +// The example displays the following output: +// Converted 0x80 to -128. +// Converted 0xE293 to -7533. +// Converted 0xF9A2FF to -417025. +// Converted 0xFFFFFFFF to -1. +// Converted 0x080 to 128. +// Converted 0x0E293 to 58003. +// Converted 0x0F9A2FF to 16360191. +// Converted 0x0FFFFFFFF to 4294967295. +// Converted 0x0080 to 128. +// Converted 0x00E293 to 58003. +// Converted 0x00F9A2FF to 16360191. +// Converted 0x00FFFFFFFF to 4294967295. +// diff --git a/snippets/fsharp/System.Numerics/BigInteger/TryParse/fs.fsproj b/snippets/fsharp/System.Numerics/BigInteger/TryParse/fs.fsproj new file mode 100644 index 00000000000..7051a697198 --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/TryParse/fs.fsproj @@ -0,0 +1,12 @@ + + + Exe + net8.0 + + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.fs b/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.fs new file mode 100644 index 00000000000..445836a259d --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.fs @@ -0,0 +1,416 @@ +module operator1 + +open System +open System.Numerics + +let bitwiseAnd () = + // + let number1 = BigInteger.Add(Int64.MaxValue, Int32.MaxValue) + let number2 = BigInteger.Pow(Byte.MaxValue, 10) + let result = number1 &&& number2 + // + () + +let bitwiseOr () = + // + let number1 = BigInteger.Parse("10343901200000000000") + let number2 = Byte.MaxValue + let result = number1 ||| number2 + // + () + +let decrement () = + // + let number1 = BigInteger.Pow(Int32.MaxValue, 2) + let number1 = BigInteger.Subtract(number1, BigInteger.One) + // + () + +let equalsInt641 () = + // + let bigNumber = BigInteger.Pow(2, 63) + let number = Int64.MaxValue + + if bigint number = bigNumber then + // Do something... + // + () + + () + +let equalsInt642 () = + // + let bigNumber = BigInteger.Pow(2, 63) + let number = Int64.MaxValue + + if bigNumber = number then + // Do something... + // + () + + () + +let equalsUInt641 () = + // + let bigNumber = BigInteger.Pow(2, 63) - BigInteger.One + let uNumber = uint64 Int64.MaxValue &&& 0x7FFFFFFFFFFFFFFFuL + + if bigNumber = uNumber then + // Do something... + // + () + + () + +let equalsUInt642 () = + // + let bigNumber = BigInteger.Pow(2, 63) - BigInteger.One + let uNumber = uint64 Int64.MaxValue &&& 0x7FFFFFFFFFFFFFFFuL + + if bigint uNumber = bigNumber then + // Do something... + // + () + + () + +let bitwiseXOr () = + // + let number1 = BigInteger.Pow(2, 127) + let number2 = BigInteger.Multiply(163, 124) + let result = number1 ^^^ number2 + // + Console.WriteLine("XOR: " + result.ToString()) + +let greaterThan64B () = + // + let bigNumber = BigInteger.Pow(Int32.MaxValue, 4) + let number = Int64.MaxValue + + if bigint number > bigNumber then + // Do something; + // + () + + () +// Snipppet10: calling op_GreaterThan(Int64, BigInteger) directly is +// not supported. + +let greaterThanB64 () = + // + let bigNumber = BigInteger.Pow(Int32.MaxValue, 4) + let number = Int64.MaxValue + + if bigNumber > number then + // Do something; + // + () + + () +// Snipppet12: calling op_GreaterThan(BigInteger, Int64) directly is +// not supported. + +let greaterThanBU64 () = + // + let bigNumber = BigInteger.Pow(Int32.MaxValue, 2) + let number = UInt64.MaxValue + + if bigNumber > number then + // Do something + // + () + + () + +let greaterThanU64B () = + // + let bigNumber = BigInteger.Pow(Int32.MaxValue, 2) + let number = UInt64.MaxValue + + if bigint number > bigNumber then + // Do something + // + () + + () + +let greaterThanOrEqual64B () = + // + let bigNumber = BigInteger.Pow(Int32.MaxValue, 4) + let number = Int64.MaxValue + + if bigint number >= bigNumber then + // Do something; + // + () + + () + +let greaterThanOrEqualB64 () = + // + let bigNumber = BigInteger.Pow(Int32.MaxValue, 4) + let number = Int64.MaxValue + + if bigNumber >= number then + // Do something; + // + () + + () + +let greaterThanOrEqualBU64 () = + // + let bigNumber = BigInteger.Pow(Int32.MaxValue, 2) + let number = UInt64.MaxValue + + if bigNumber >= number then + // Do something + // + () + + () + +let greaterThanOrEqualU64B () = + // + let bigNumber = BigInteger.Pow(Int32.MaxValue, 2) + let number = UInt64.MaxValue + + if bigint number >= bigNumber then + // Do something + // + () + + () + +let inequality64B () = + // + let bigNumber = BigInteger.Pow(2, 63) + let number = Int64.MaxValue + + if bigint number <> bigNumber then + // Do something... + // + () + + () + +let inequalityB64 () = + // + let bigNumber = BigInteger.Pow(2, 63) + let number = Int64.MaxValue + + if bigNumber <> number then + // Do something... + // + () + + () + +let inequalityBU64 () = + // + let bigNumber = BigInteger.Pow(2, 63) - BigInteger.One + let uNumber = uint64 Int64.MaxValue &&& 0x7FFFFFFFFFFFFFFFuL + + if bigNumber <> uNumber then + // Do something... + // + () + + () + +let inequalityU64B () = + // + let bigNumber = BigInteger.Pow(2, 63) - BigInteger.One + let uNumber = uint64 Int64.MaxValue &&& 0x7FFFFFFFFFFFFFFFuL + + if bigint uNumber <> bigNumber then + // Do something... + // + () + + () + +let leftShift () = + // + let number = BigInteger.Parse "-9047321678449816249999312055" + printfn $"Shifting {number} left by:" + + for ctr = 0 to 16 do + let newNumber = number <<< ctr + printfn $" {ctr, 2} bits: {newNumber, 35} {newNumber:X}" +// The example displays the following output: +// Shifting -9047321678449816249999312055 left by: +// 0 bits: -9047321678449816249999312055 E2C43B1D0D6F07D2CC1FBB49 +// 1 bits: -18094643356899632499998624110 C588763A1ADE0FA5983F7692 +// 2 bits: -36189286713799264999997248220 8B10EC7435BC1F4B307EED24 +// 3 bits: -72378573427598529999994496440 F1621D8E86B783E9660FDDA48 +// 4 bits: -1.4475714685519705999998899288E+29 E2C43B1D0D6F07D2CC1FBB490 +// 5 bits: -2.8951429371039411999997798576E+29 C588763A1ADE0FA5983F76920 +// 6 bits: -5.7902858742078823999995597152E+29 8B10EC7435BC1F4B307EED240 +// 7 bits: -1.158057174841576479999911943E+30 F1621D8E86B783E9660FDDA480 +// 8 bits: -2.3161143496831529599998238861E+30 E2C43B1D0D6F07D2CC1FBB4900 +// 9 bits: -4.6322286993663059199996477722E+30 C588763A1ADE0FA5983F769200 +// 10 bits: -9.2644573987326118399992955443E+30 8B10EC7435BC1F4B307EED2400 +// 11 bits: -1.8528914797465223679998591089E+31 F1621D8E86B783E9660FDDA4800 +// 12 bits: -3.7057829594930447359997182177E+31 E2C43B1D0D6F07D2CC1FBB49000 +// 13 bits: -7.4115659189860894719994364355E+31 C588763A1ADE0FA5983F7692000 +// 14 bits: -1.4823131837972178943998872871E+32 8B10EC7435BC1F4B307EED24000 +// 15 bits: -2.9646263675944357887997745742E+32 F1621D8E86B783E9660FDDA48000 +// 16 bits: -5.9292527351888715775995491484E+32 E2C43B1D0D6F07D2CC1FBB490000 +// + +let leftShiftManually () = + // + let number = BigInteger.Parse "-9047321678449816249999312055" + printfn $"Shifting {number} left by:" + + for ctr = 0 to 16 do + let newNumber = number * BigInteger.Pow(2, ctr) + printfn $" {ctr, 2} bits: {newNumber, 35} {newNumber:X}" +// The example displays the following output: +// Shifting -9047321678449816249999312055 left by: +// 0 bits: -9047321678449816249999312055 E2C43B1D0D6F07D2CC1FBB49 +// 1 bits: -18094643356899632499998624110 C588763A1ADE0FA5983F7692 +// 2 bits: -36189286713799264999997248220 8B10EC7435BC1F4B307EED24 +// 3 bits: -72378573427598529999994496440 F1621D8E86B783E9660FDDA48 +// 4 bits: -1.4475714685519705999998899288E+29 E2C43B1D0D6F07D2CC1FBB490 +// 5 bits: -2.8951429371039411999997798576E+29 C588763A1ADE0FA5983F76920 +// 6 bits: -5.7902858742078823999995597152E+29 8B10EC7435BC1F4B307EED240 +// 7 bits: -1.158057174841576479999911943E+30 F1621D8E86B783E9660FDDA480 +// 8 bits: -2.3161143496831529599998238861E+30 E2C43B1D0D6F07D2CC1FBB4900 +// 9 bits: -4.6322286993663059199996477722E+30 C588763A1ADE0FA5983F769200 +// 10 bits: -9.2644573987326118399992955443E+30 8B10EC7435BC1F4B307EED2400 +// 11 bits: -1.8528914797465223679998591089E+31 F1621D8E86B783E9660FDDA4800 +// 12 bits: -3.7057829594930447359997182177E+31 E2C43B1D0D6F07D2CC1FBB49000 +// 13 bits: -7.4115659189860894719994364355E+31 C588763A1ADE0FA5983F7692000 +// 14 bits: -1.4823131837972178943998872871E+32 8B10EC7435BC1F4B307EED24000 +// 15 bits: -2.9646263675944357887997745742E+32 F1621D8E86B783E9660FDDA48000 +// 16 bits: -5.9292527351888715775995491484E+32 E2C43B1D0D6F07D2CC1FBB490000 +// + +let lessThan64B () = + // + let number = BigInteger.Parse "9801324316220166912" + + if bigint Int64.MaxValue < number then + // Do something. + () + else + // Do something else. + () + // + +let lessThanB64 () = + // + let number = BigInteger.Parse "9801324316220166912" + + if number < Int64.MaxValue then + // Do something. + () + else + // Do something else. + () + // + +let lessThanBU64 () = + // + let number = BigInteger.Parse "19801324316220166912" + + if number < UInt64.MaxValue then + // Do something. + () + else + // Do something else. + () + // + +let lessThanU64B () = + // + let number = BigInteger.Parse "9801324316220166912" + + if bigint UInt64.MaxValue < number then + // Do something. + () + else + // Do something else. + () + // + +let lessThanOrEqual64B () = + // + let number = BigInteger.Parse "9801324316220166912" + + if bigint Int64.MaxValue <= number then + // Do something. + () + else + // Do something else. + () + // + +let lessThanOrEqualB64 () = + // + let number = BigInteger.Parse "9801324316220166912" + + if number <= Int64.MaxValue then + // Do something. + () + else + // Do something else. + () + // + +let lessThanOrEqualBU64 () = + // + let number = BigInteger.Parse "19801324316220166912" + + if number <= UInt64.MaxValue then + // Do something. + () + else + // Do something else. + () + // + +let lessThanOrEqualU64B () = + // + let number = BigInteger.Parse "9801324316220166912" + + if bigint UInt64.MaxValue <= number then + // Do something. + () + else + // Do something else. + () + // + +bitwiseAnd () +bitwiseOr () +decrement () +equalsInt641 () +equalsInt642 () +equalsUInt641 () +equalsUInt642 () +bitwiseXOr () +greaterThan64B () +greaterThanB64 () +greaterThanBU64 () +greaterThanU64B () +greaterThanOrEqual64B () +greaterThanOrEqualB64 () +greaterThanOrEqualBU64 () +greaterThanOrEqualU64B () +inequality64B () +inequalityB64 () +inequalityBU64 () +inequalityU64B () +leftShift () +leftShiftManually () +lessThan64B () +lessThanB64 () +lessThanBU64 () +lessThanU64B () +lessThanOrEqual64B () +lessThanOrEqualB64 () +lessThanOrEqualBU64 () +lessThanOrEqualU64B () diff --git a/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/RightShift1.fs b/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/RightShift1.fs new file mode 100644 index 00000000000..e6b4fc97250 --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/RightShift1.fs @@ -0,0 +1,68 @@ +module rightshift1 + +open System.Numerics + +let rightShift () = + // + let number = BigInteger.Parse "-9047321678449816249999312055" + printfn $"Shifting {number} right by:" + + for ctr = 0 to 16 do + let newNumber = number >>> ctr + printfn $" {ctr, 2} bits: {newNumber, 35} {newNumber:X}" + // The example displays the following output: + // Shifting -9047321678449816249999312055 right by: + // 0 bits: -9047321678449816249999312055 E2C43B1D0D6F07D2CC1FBB49 + // 1 bits: -4523660839224908124999656028 F1621D8E86B783E9660FDDA4 + // 2 bits: -2261830419612454062499828014 8B10EC7435BC1F4B307EED2 + // 3 bits: -1130915209806227031249914007 C588763A1ADE0FA5983F769 + // 4 bits: -565457604903113515624957004 E2C43B1D0D6F07D2CC1FBB4 + // 5 bits: -282728802451556757812478502 F1621D8E86B783E9660FDDA + // 6 bits: -141364401225778378906239251 8B10EC7435BC1F4B307EED + // 7 bits: -70682200612889189453119626 C588763A1ADE0FA5983F76 + // 8 bits: -35341100306444594726559813 E2C43B1D0D6F07D2CC1FBB + // 9 bits: -17670550153222297363279907 F1621D8E86B783E9660FDD + // 10 bits: -8835275076611148681639954 8B10EC7435BC1F4B307EE + // 11 bits: -4417637538305574340819977 C588763A1ADE0FA5983F7 + // 12 bits: -2208818769152787170409989 E2C43B1D0D6F07D2CC1FB + // 13 bits: -1104409384576393585204995 F1621D8E86B783E9660FD + // 14 bits: -552204692288196792602498 8B10EC7435BC1F4B307E + // 15 bits: -276102346144098396301249 C588763A1ADE0FA5983F + // 16 bits: -138051173072049198150625 E2C43B1D0D6F07D2CC1F + // + +let rightShiftManually () = + // + let number = BigInteger.Parse "-9047321678449816249999312055" + printfn $"Shifting {number} right by:" + + for ctr = 0 to 16 do + let mutable newNumber = number / BigInteger.Pow(2, ctr) + + if newNumber * bigint ctr < 0 then + newNumber <- newNumber - bigint 1 + + printfn $" {ctr, 2} bits: {newNumber, 35} {newNumber:X}" + // The example displays the following output: + // 0 bits: -9047321678449816249999312055 E2C43B1D0D6F07D2CC1FBB49 + // 1 bits: -4523660839224908124999656028 F1621D8E86B783E9660FDDA4 + // 2 bits: -2261830419612454062499828014 8B10EC7435BC1F4B307EED2 + // 3 bits: -1130915209806227031249914007 C588763A1ADE0FA5983F769 + // 4 bits: -565457604903113515624957004 E2C43B1D0D6F07D2CC1FBB4 + // 5 bits: -282728802451556757812478502 F1621D8E86B783E9660FDDA + // 6 bits: -141364401225778378906239251 8B10EC7435BC1F4B307EED + // 7 bits: -70682200612889189453119626 C588763A1ADE0FA5983F76 + // 8 bits: -35341100306444594726559813 E2C43B1D0D6F07D2CC1FBB + // 9 bits: -17670550153222297363279907 F1621D8E86B783E9660FDD + // 10 bits: -8835275076611148681639954 8B10EC7435BC1F4B307EE + // 11 bits: -4417637538305574340819977 C588763A1ADE0FA5983F7 + // 12 bits: -2208818769152787170409989 E2C43B1D0D6F07D2CC1FB + // 13 bits: -1104409384576393585204995 F1621D8E86B783E9660FD + // 14 bits: -552204692288196792602498 8B10EC7435BC1F4B307E + // 15 bits: -276102346144098396301249 C588763A1ADE0FA5983F + // 16 bits: -138051173072049198150625 E2C43B1D0D6F07D2CC1F + // + + +rightShift () +rightShiftManually () diff --git a/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/fs.fsproj b/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/fs.fsproj new file mode 100644 index 00000000000..3ba03ad3853 --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/fs.fsproj @@ -0,0 +1,11 @@ + + + Exe + net8.0 + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/BigInteger/op_Explicit/Explicit1.fs b/snippets/fsharp/System.Numerics/BigInteger/op_Explicit/Explicit1.fs new file mode 100644 index 00000000000..f6e52090595 --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/op_Explicit/Explicit1.fs @@ -0,0 +1,135 @@ +module explicit1 + +open System +open System.Numerics + +let explicitFromDecimal () = + // Explicit Decimal to BigInteger conversion + // + let decimals = [| Decimal.MinValue; -15632.991m; 9029321.12m; Decimal.MaxValue |] + + printfn "%35s %35s\n" "Decimal" "BigInteger" + + for value in decimals do + let number = BigInteger(value) + printfn "%35O %35O" value number + // The example displays the following output: + // + // Decimal BigInteger + // + // -79228162514264337593543950335 -79228162514264337593543950335 + // -15632.991 -15632 + // 9029321.12 9029321 + // 79228162514264337593543950335 79228162514264337593543950335 + // + + +let explicitFromDouble () = + // + let doubles = + [| Double.MinValue + -1.430955172e03 + 2.410970032e05 + Double.MaxValue + Double.PositiveInfinity + Double.NegativeInfinity + Double.NaN |] + + printfn "%37s %37s\n" "Double" "BigInteger" + + for value in doubles do + try + let number = BigInteger(value) + printfn "%37O %37O" value number + with :? OverflowException -> + printfn "%37O %37s" value "OverflowException" + // The example displays the following output: + // Double BigInteger + // + // -1.79769313486232E+308 -1.7976931348623157081452742373E+308 + // -1430.955172 -1430 + // 241097.0032 241097 + // 1.79769313486232E+308 1.7976931348623157081452742373E+308 + // Infinity OverflowException + // -Infinity OverflowException + // NaN OverflowException + // + +let explicitFromSingle () = + // + let singles = + [| Single.MinValue + -1.430955172e03f + 2.410970032e05f + Single.MaxValue + Single.PositiveInfinity + Single.NegativeInfinity + Single.NaN |] + + printfn "%37s %37s\n" "Single" "BigInteger" + + for value in singles do + try + let number = BigInteger(value) + printfn "%37O %37O" value number + with :? OverflowException -> + printfn "%37O %37s" value "OverflowException" + // The example displays the following output: + // Single BigInteger + // + // -3.402823E+38 -3.4028234663852885981170418348E+38 + // -1430.955 -1430 + // 241097 241097 + // 3.402823E+38 3.4028234663852885981170418348E+38 + // Infinity OverflowException + // -Infinity OverflowException + // NaN OverflowException + // + +let doublePrecision () = + // + // Increase a BigInteger so it exceeds Double.MaxValue. + let number1 = bigint Double.MaxValue + let number2 = number1 + bigint 9.999e291 + // Compare the BigInteger values for equality. + printfn $"BigIntegers equal: {number2.Equals number1}" + + // Convert the BigInteger to a Double. + let dbl = float number2 + + // Display the two values. + printfn $"BigInteger: {number2}" + printfn $"Double: {dbl}" + // The example displays the following output: + // BigIntegers equal: False + // BigInteger: 1.7976931348623158081352742373E+308 + // Double: 1.79769313486232E+308 + // + +let singlePrecision () = + // + // Increase a BigInteger so it exceeds Single.MaxValue. + let number1 = bigint Single.MaxValue + + let number2 = number1 + bigint 9.999e30 + // Compare the BigInteger values for equality. + printfn $"BigIntegers equal: {number2.Equals number1}" + + // Convert the BigInteger to a Single. + let sng = float32 number2 + + // Display the two values. + printfn $"BigInteger: {number2}" + printfn $"Single: {sng}" + // The example displays the following output: + // BigIntegers equal: False + // BigInteger: 3.4028235663752885981170396038E+38 + // Single: 3.402823E+38 + // + + +explicitFromDecimal () +explicitFromDouble () +explicitFromSingle () +doublePrecision () +singlePrecision () diff --git a/snippets/fsharp/System.Numerics/BigInteger/op_Explicit/System.Numeric.BigInteger.Explicit.fs b/snippets/fsharp/System.Numerics/BigInteger/op_Explicit/System.Numeric.BigInteger.Explicit.fs new file mode 100644 index 00000000000..61e352f5fe2 --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/op_Explicit/System.Numeric.BigInteger.Explicit.fs @@ -0,0 +1,237 @@ +module explicit + +open System +open System.Numerics + +// +// BigInteger to Byte conversion. +let goodByte = BigInteger.One +let badByte = bigint 256 + +// Successful conversion using cast operator. +let byteFromBigInteger = byte goodByte +printfn $"{byteFromBigInteger}" + +// Handle conversion that should result in overflow. +try + let byteFromBigInteger = byte badByte + printfn $"{byteFromBigInteger}" +with :? OverflowException as e -> + printfn $"Unable to convert {badByte}:\n {e.Message}" +// + +// +// BigInteger to Decimal conversion. +let goodDecimal = 761652543 +let badDecimal = bigint Decimal.MaxValue + BigInteger.One + +// Successful conversion using cast operator. +let decimalFromBigInteger = decimal goodDecimal +printfn $"{decimalFromBigInteger}" + +// Handle conversion that should result in overflow. +try + let decimalFromBigInteger = decimal badDecimal + printfn $"{decimalFromBigInteger}" +with :? OverflowException as e -> + printfn $"Unable to convert {badDecimal}:\n {e.Message}" +// + +do + // + // BigInteger to Double conversion. + let goodDouble = bigint 102.43e22 + let badDouble = bigint Double.MaxValue * bigint 2 + + // successful conversion using cast operator. + let doubleFromBigInteger = double goodDouble + printfn $"{doubleFromBigInteger}" + + // Convert an out-of-bounds BigInteger value to a Double. + let doubleFromBigInteger = double badDouble + printfn $"{doubleFromBigInteger}" + // + +// +// BigInteger to Int16 conversion. +let goodShort = bigint 20000 +let badShort = bigint 33000 + +// Successful conversion using cast operator. +let shortFromBigInteger = int16 goodShort +printfn $"{shortFromBigInteger}" + +// Handle conversion that should result in overflow. +try + let shortFromBigInteger = int16 badShort + printfn $"{shortFromBigInteger}" +with :? OverflowException as e -> + printfn $"Unable to convert {badShort}:\n {e.Message}" +// + +// +// BigInteger to Int32 conversion. +let goodInteger = bigint 200000 +let badInteger = bigint 65000000000L + +// Successful conversion using cast operator. +let integerFromBigInteger = int goodInteger +printfn $"{integerFromBigInteger}" + +// Handle conversion that should result in overflow. +try + let integerFromBigInteger = int badInteger + printfn $"{integerFromBigInteger}" +with :? OverflowException as e -> + printfn $"Unable to convert {badInteger}:\n {e.Message}" +// + +// +// BigInteger to Int64 conversion. +let goodLong = 2000000000 +let badLong = BigInteger.Pow(goodLong, 3) + +// Successful conversion using cast operator. +let longFromBigInteger = int64 goodLong +printfn $"{longFromBigInteger}" + +// Handle conversion that should result in overflow. +try + let longFromBigInteger = int64 badLong + printfn $"{longFromBigInteger}" +with :? OverflowException as e -> + printfn $"Unable to convert {badLong}:\n {e.Message}" +// + +// +// BigInteger to SByte conversion. +let goodSByte = BigInteger.MinusOne +let badSByte = bigint -130 + +// Successful conversion using cast operator. +let sByteFromBigInteger = sbyte goodSByte +printfn $"{sByteFromBigInteger}" + +// Handle conversion that should result in overflow. +try + let sByteFromBigInteger = sbyte badSByte + printfn $"{sByteFromBigInteger}" +with :? OverflowException as e -> + printfn $"Unable to convert {badSByte}:\n {e.Message}" +// + +do + // + // BigInteger to Single conversion. + let goodSingle = bigint 102.43e22F + let badSingle = bigint Single.MaxValue * bigint 2 + + // Successful conversion using cast operator. + let singleFromBigInteger = float32 goodSingle + printfn $"{singleFromBigInteger}" + + // Convert an out-of-bounds BigInteger value to a Single. + let singleFromBigInteger = float32 badSingle + printfn $"{singleFromBigInteger}" + // + +// +// BigInteger to UInt16 conversion. +let goodUShort = bigint 20000 +let badUShort = bigint 66000 + +// Successful conversion using cast operator. +let uShortFromBigInteger = uint16 goodUShort +printfn $"{uShortFromBigInteger}" + +// Handle conversion that should result in overflow. +try + let uShortFromBigInteger = uint16 badUShort + printfn $"{uShortFromBigInteger}" +with :? OverflowException as e -> + printfn $"Unable to convert {badSByte}:\n {e.Message}" + +// + +// +// BigInteger to UInt32 conversion. +let goodUInteger = bigint 200000 +let badUInteger = bigint 65000000000L + +// Successful conversion using cast operator. +let uIntegerFromBigInteger = uint goodInteger +printfn $"{uIntegerFromBigInteger}" + +// Handle conversion that should result in overflow. +try + let uIntegerFromBigInteger = uint badUInteger + printfn $"{uIntegerFromBigInteger}" +with :? OverflowException as e -> + printfn $"Unable to convert {badUInteger}:\n {e.Message}" + +// + +// +// BigInteger to UInt64 conversion. +let goodULong = bigint 2000000000 +let badULong = BigInteger.Pow(goodULong, 3) + +// Successful conversion using cast operator. +let uLongFromBigInteger = uint64 goodULong +printfn $"{uLongFromBigInteger}" + +// Handle conversion that should result in overflow. +try + let uLongFromBigInteger = uint64 badULong + printfn $"{uLongFromBigInteger}" +with :? OverflowException as e -> + printfn $"Unable to convert {badULong}:\n {e.Message}" +// + +do + // + // BigInteger to Decimal conversion. + // + // Assign a decimal to a BigInteger + let decimalValue = 31043639504.621m + let hugeValueFromDecimal = bigint decimalValue + let hugeValueFromDecimal = BigInteger.Pow(hugeValueFromDecimal, 2) + // Convert the value back to a Decimal if it's in range + if hugeValueFromDecimal <= bigint Decimal.MaxValue then + let decimalValue = decimal hugeValueFromDecimal + printfn $"The decimal value is {decimalValue}" + else + printfn $"Unable to convert {hugeValueFromDecimal} to a Decimal" + // + +do + // + // BigInteger to Double conversion. + // + // Assign a Double to a BigInteger + let doubleValue = 3104363950465.621984 + let hugeValueFromDouble = bigint doubleValue + let hugeValueFromDouble = BigInteger.Pow(hugeValueFromDouble, 3) + // Convert the value back to a Decimal if it's in range + if hugeValueFromDouble <= bigint Double.MaxValue then + let doubleValue = double hugeValueFromDouble + printfn $"The value of the Double is {doubleValue}" + else + printfn $"Unable to convert {hugeValueFromDouble} to a Double" + // + +do + // + // BigInteger to float conversion. + // + // Assign a float to a BigInteger + let singleValue = 3104363950465.621984F + let hugeValueFromSingle = bigint singleValue + let hugeValueFromSingle = BigInteger.Pow(hugeValueFromSingle, 2) + // Convert the value back to a Single if it//s in range + if hugeValueFromSingle <= bigint Single.MaxValue then + let singleValue = float32 hugeValueFromSingle + printfn $"The value of the float is {singleValue}" + else + printfn $"Unable to convert {hugeValueFromSingle} to a float" + // diff --git a/snippets/fsharp/System.Numerics/BigInteger/op_Explicit/fs.fsproj b/snippets/fsharp/System.Numerics/BigInteger/op_Explicit/fs.fsproj new file mode 100644 index 00000000000..82b5bcc8d0d --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/op_Explicit/fs.fsproj @@ -0,0 +1,11 @@ + + + Exe + net8.0 + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/BigInteger/op_Implicit/Implicit1.fs b/snippets/fsharp/System.Numerics/BigInteger/op_Implicit/Implicit1.fs new file mode 100644 index 00000000000..8659980044f --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/op_Implicit/Implicit1.fs @@ -0,0 +1,92 @@ +open System.Numerics + +let showByteConversion () = + printfn "Implicit Byte Conversion:" + // + let byteValue = 254uy + let number = BigInteger(byteValue) + let mutable number = BigInteger.Add(number, byteValue) + printfn $"{number > byteValue}" // Displays True + // + printfn "" + +let showShortConversion () = + printfn "Implicit Short Conversion:" + // + let shortValue = 25064s + let number = BigInteger(shortValue) + let mutable number = BigInteger.Add(number, shortValue) + printfn $"{number > shortValue}" // Displays False + // + printfn "" + + +let showIntConversion () = + printfn "Implicit Int Conversion:" + // + let intValue = 65000 + let number = BigInteger(intValue) + let mutable number = BigInteger.Multiply(number, intValue) + printfn $"{number = intValue}" // Displays False + // + printfn "" + +let showLongConversion () = + printfn "Implicit Long Conversion:" + // + let longValue = 1358754982L + let number = BigInteger longValue + let mutable number = BigInteger.Add(number, longValue / 2L |> bigint) + printfn $"{((number * bigint longValue) / (bigint longValue))}" // Displays 2038132473 + + // + printfn "" + +let showSByteConversion () = + printfn "Implicit SByte Conversion:" + // + let sByteValue = -12y + let number = BigInteger.Pow(sByteValue, 3) + printfn $"{number < sByteValue}" // Displays True + // + printfn "" + + +let showUShortConversion () = + printfn "Implicit UShort Conversion:" + // + let uShortValue = 25064us + let number = BigInteger(uShortValue) + let mutable number = BigInteger.Add(number, uShortValue) + printfn $"{number < uShortValue}" // Displays False + // + printfn "" + +let showUIntConversion () = + printfn "Implicit UInt Conversion:" + // + let uIntValue = 65000u + let number = BigInteger(uIntValue) + let mutable number = BigInteger.Multiply(number, uIntValue) + printfn $"{number = uIntValue}" // Displays "False + // + printfn "" + +let showULongConversion () = + printfn "Implicit ULong Conversion:" + // + let uLongValue = 1358754982UL + let number = BigInteger(uLongValue) + let mutable number = BigInteger.Add(number, uLongValue / 2UL |> bigint) + printfn $"{number * bigint uLongValue / bigint uLongValue}" // Displays 1358754982 + // + printfn "" + +showByteConversion () +showShortConversion () +showIntConversion () +showLongConversion () +showSByteConversion () +showUShortConversion () +showUIntConversion () +showULongConversion () diff --git a/snippets/fsharp/System.Numerics/BigInteger/op_Implicit/fs.fsproj b/snippets/fsharp/System.Numerics/BigInteger/op_Implicit/fs.fsproj new file mode 100644 index 00000000000..ef6c530c68d --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/op_Implicit/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/BigInteger/op_OnesComplement/OnesComplement1.fs b/snippets/fsharp/System.Numerics/BigInteger/op_OnesComplement/OnesComplement1.fs new file mode 100644 index 00000000000..0e30c42e3cc --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/op_OnesComplement/OnesComplement1.fs @@ -0,0 +1,32 @@ +// +open System +open System.Numerics + +let displayInBinary (number: bigint) = + let bytes = number.ToByteArray() + let mutable binaryString = "" + + for byteValue in bytes do + let byteString = Convert.ToString(byteValue, 2).Trim() + binaryString <- binaryString + byteString.PadLeft(8, '0') + + binaryString + +let value = BigInteger.Multiply(BigInteger.One, 9) +let complement = ~~~(int64 value) |> bigint + +printfn "%5O -- %s" value (displayInBinary value) +printfn "%5O -- %s\n" complement (displayInBinary complement) + +let value2 = BigInteger.MinusOne * (bigint SByte.MaxValue) +let complement2 = ~~~(int64 value) |> bigint + +printfn "%5O -- %s" value2 (displayInBinary value2) +printfn "%5O -- %s" complement2 (displayInBinary complement2) +// The example displays the following output: +// 9 -- 00001001 +// -10 -- 11110110 +// +// -127 -- 10000001 +// 126 -- 01111110 +// diff --git a/snippets/fsharp/System.Numerics/BigInteger/op_OnesComplement/fs.fsproj b/snippets/fsharp/System.Numerics/BigInteger/op_OnesComplement/fs.fsproj new file mode 100644 index 00000000000..5ccbe39fb45 --- /dev/null +++ b/snippets/fsharp/System.Numerics/BigInteger/op_OnesComplement/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/xml/System.Numerics/BigInteger.xml b/xml/System.Numerics/BigInteger.xml index 5153b0e99d8..22a942d56c4 100644 --- a/xml/System.Numerics/BigInteger.xml +++ b/xml/System.Numerics/BigInteger.xml @@ -319,16 +319,19 @@ The following example instantiates a object from a 5-element byte array whose value is {5, 4, 3, 2, 1}. It then displays the value, represented as both decimal and hexadecimal numbers, to the console. A comparison of the input array with the text output makes it clear why this overload of the class constructor creates a object whose value is 4328719365 (or 0x102030405). The first element of the byte array, whose value is 5, defines the value of the lowest-order byte of the object, which is 0x05. The second element of the byte array, whose value is 4, defines the value of the second byte of the object, which is 0x04, and so on. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/.ctor/Example1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/.ctor/Example1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.ctors/vb/Example1.vb" id="Snippet1"::: The following example instantiates a positive and a negative value, passes them to the method, and then restores the original values from the resulting byte array. Note that the two values are represented by identical byte arrays. The only difference between them is in the most significant bit of the last element in the byte array. This bit is set (the value of the byte is 0xFF) if the array is created from a negative value. The bit is not set (the value of the byte is zero), if the array is created from a positive value. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/.ctor/Example1.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/.ctor/Example1.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.ctors/vb/Example1.vb" id="Snippet2"::: The following example illustrates how to make sure that a positive value is not incorrectly instantiated as a negative value by adding a byte whose value is zero to the end of the array. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/.ctor/Example1.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/.ctor/Example1.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.ctors/vb/Example1.vb" id="Snippet3"::: ]]> @@ -388,6 +391,7 @@ The following example illustrates the use of the constructor to instantiate a object. It defines an array of values, and then passes each value to the constructor. Note that the value is truncated instead of rounded when it is assigned to the object. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/.ctor/Example2.cs" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/.ctor/Example2.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.ctors/vb/Example2.vb" id="Snippet4"::: ]]> @@ -446,6 +450,7 @@ The following example illustrates the use of the constructor to instantiate a object. It also illustrates the loss of precision that may occur when you use the data type. A is assigned a large value, which is then assigned to a object. As the output shows, this assignment involves a loss of precision. Both values are then incremented by one. The output shows that the object reflects the changed value, whereas the object does not. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/.ctor/Example2.cs" id="Snippet5"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/.ctor/Example2.fs" id="Snippet5"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.ctors/vb/Example2.vb" id="Snippet5"::: ]]> @@ -506,6 +511,7 @@ The following example calls the constructor to instantiate values from an array of 32-bit integers. It also uses implicit conversion to assign each 32-bit integer value to a variable. It then compares the two values to establish that the resulting values are the same. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/.ctor/Example2.cs" id="Snippet6"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/.ctor/Example2.fs" id="Snippet6"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.ctors/vb/Example2.vb" id="Snippet6"::: ]]> @@ -562,6 +568,7 @@ The following example calls the constructor to instantiate values from an array of 64-bit integers. It also uses implicit conversion to assign each 64-bit integer value to a variable. It then compares the two values to establish that the resulting values are the same. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/.ctor/Example2.cs" id="Snippet7"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/.ctor/Example2.fs" id="Snippet7"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.ctors/vb/Example2.vb" id="Snippet7"::: ]]> @@ -620,6 +627,7 @@ The following example illustrates the use of the constructor to instantiate a object. It also illustrates the loss of precision that may occur when you use the data type. A is assigned a large negative value, which is then assigned to a object. As the output shows, this assignment involves a loss of precision. Both values are then incremented by one. The output shows that the object reflects the changed value, whereas the object does not. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/.ctor/Example2.cs" id="Snippet8"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/.ctor/Example2.fs" id="Snippet8"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.ctors/vb/Example2.vb" id="Snippet8"::: ]]> @@ -684,6 +692,7 @@ The following example uses the constructor and an assignment statement to initialize values from an array of unsigned 32-bit integers. It then compares the two values to demonstrate that the two methods of initializing a value produce identical results. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/.ctor/Example2.cs" id="Snippet9"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/.ctor/Example2.fs" id="Snippet9"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.ctors/vb/Example2.vb" id="Snippet9"::: ]]> @@ -747,6 +756,7 @@ The following example uses the constructor to instantiate a object whose value is equal to . :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/.ctor/Example2.cs" id="Snippet10"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/.ctor/Example2.fs" id="Snippet10"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.ctors/vb/Example2.vb" id="Snippet10"::: ]]> @@ -912,6 +922,7 @@ The method is a useful substitute for the addition operator when instantiating a variable by assigning it a sum that results from addition, as shown in the following example. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/Add/Multiply1.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/Add/Multiply1.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.OperationMethods/vb/Multiply1.vb" id="Snippet2"::: ]]> @@ -1027,6 +1038,7 @@ Although the type has no fixed range, comparisons of values are not characterized by the lack of precision that characterizes the comparison of floating-point numbers. The following example compares two values that differ by one and that each have 1,896 digits. The method correctly reports that the two values are not equal. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/Compare/Compare1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/Compare/Compare1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Compare/vb/Compare1.vb" id="Snippet1"::: ]]> @@ -1114,6 +1126,7 @@ The following example illustrates the result of calling the method with integral values. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/CompareTo/Example2.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/CompareTo/Example2.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.CompareTo/vb/Example2.vb" id="Snippet3"::: ]]> @@ -1193,11 +1206,13 @@ The following example illustrates the use of the method to order a list of `StarInfo` objects. Each `StarInfo` object provides information about a star's name and its distance from the Earth in miles. `StarInfo` implements the interface, which enables `StarInfo` objects to be sorted by generic collection classes. Its implementation just wraps a call to . :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/CompareTo/Example1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/CompareTo/Example1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.CompareTo/vb/Example1.vb" id="Snippet1"::: The following code then instantiates four `StarInfo` objects and stores them in a generic object. After the method is called, `StarInfo` objects are displayed in order of their distance from the Earth. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/CompareTo/Example1.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/CompareTo/Example1.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.CompareTo/vb/Example1.vb" id="Snippet2"::: ]]> @@ -1292,6 +1307,7 @@ The following example calls the method to compare a value with each element in an object array: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/CompareTo/Example2.cs" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/CompareTo/Example2.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.CompareTo/vb/Example2.vb" id="Snippet4"::: ]]> @@ -1623,6 +1639,7 @@ The following example creates an array of values. It then uses each element as the quotient in a division operation that uses the method, the division operator (/), and the method. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/Divide/Divide1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/Divide/Divide1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Divide/vb/Divide1.vb" id="Snippet1"::: ]]> @@ -1739,6 +1756,7 @@ The following example creates an array of values. It then uses each element as the quotient in a division operation that uses the method, the division operator (/), and the method. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/Divide/Divide1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/Divide/Divide1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Divide/vb/Divide1.vb" id="Snippet1"::: ]]> @@ -1813,6 +1831,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Numerics.BigInteger.Equals/cpp/equals.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/Equals/EqualsExample1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/Equals/EqualsExample1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Equals/vb/EqualsExample1.vb" id="Snippet1"::: ]]> @@ -1878,6 +1897,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Numerics.BigInteger.Equals/cpp/equals2.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/Equals/EqualsExample1.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/Equals/EqualsExample1.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Equals/vb/EqualsExample1.vb" id="Snippet2"::: ]]> @@ -1953,6 +1973,7 @@ The following example defines parallel and arrays. Each element of one array has the same value as the corresponding element of the second array. As the output from the example shows, the instance in the array is considered to be equal to the instance in the array only if the latter is a and their values are equal. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/Equals/Equals_Obj1.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/Equals/Equals_Obj1.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Equals/vb/Equals_Obj1.vb" id="Snippet3"::: ]]> @@ -2019,6 +2040,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Numerics.BigInteger.Equals/cpp/equals2.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/Equals/EqualsExample1.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/Equals/EqualsExample1.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Equals/vb/EqualsExample1.vb" id="Snippet2"::: ]]> @@ -2204,6 +2226,7 @@ This method returns 0 if the value of current object is equal to method and the exception handling necessary to provide useful information about an . The result indicates that the greatest common divisor of these two numbers is 1. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.cs" id="Snippet10"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.fs" id="Snippet10"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Class/vb/BigInteger_Examples.vb" id="Snippet10"::: ]]> @@ -2748,6 +2771,7 @@ A return value of `false` does not imply that method along with the method. Note that the result is if the result is greater than . The following example calculates the square root of each element in an array of values. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/LogMethod/log1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/LogMethod/log1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.biginteger.log/vb/log1.vb" id="Snippet1"::: This method corresponds to the method for the primitive numeric types. @@ -2996,6 +3020,7 @@ A return value of `false` does not imply that method to select the largest number in an array of values. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/Max/Max1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/Max/Max1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Max/vb/Max1.vb" id="Snippet1"::: ]]> @@ -3109,6 +3134,7 @@ For this method matches the IEE The following example uses the method to select the smallest number in an array of values. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/Min/Min1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/Min/Min1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Min/vb/Min1.vb" id="Snippet1"::: ]]> @@ -3278,6 +3304,7 @@ For this method matches the IEE The following example provides a simple illustration of calling the method. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/ModPow/ModPow1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/ModPow/ModPow1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.ModPow/vb/ModPow1.vb" id="Snippet1"::: ]]> @@ -3344,6 +3371,7 @@ For this method matches the IEE The method is implemented for languages that do not support operator overloading. Its behavior is identical to multiplication using the multiplication operator. In addition, the method is a useful substitute for the multiplication operator when instantiating a variable by assigning it a product that results from multiplication, as shown in the following example. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/Add/Multiply1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/Add/Multiply1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.OperationMethods/vb/Multiply1.vb" id="Snippet1"::: If necessary, this method automatically performs implicit conversion of other integral types to objects. This is illustrated in the example in the next section, where the method is passed two values. @@ -3354,6 +3382,7 @@ For this method matches the IEE The following example tries to perform multiplication with two long integers. Because the result exceeds the range of a long integer, an is thrown, and the method is called to handle the multiplication. Note that C# requires that you use either the `checked` keyword (as in this example) or the `/checked+` compiler option to make sure an exception is thrown on a numeric overflow. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.cs" id="Snippet7"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.fs" id="Snippet7"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Class/vb/BigInteger_Examples.vb" id="Snippet7"::: ]]> @@ -3416,6 +3445,7 @@ For this method matches the IEE The method is implemented for languages that do not support custom operators. Its behavior is identical to negation using the unary negation operator. In addition, the method is a useful substitute for the negation operator when instantiating a variable, as shown in the following example. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/Add/Multiply1.cs" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/Add/Multiply1.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.OperationMethods/vb/Multiply1.vb" id="Snippet4"::: @@ -3424,6 +3454,7 @@ For this method matches the IEE The following example illustrates three ways to negate the value of a object. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.cs" id="Snippet16"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.fs" id="Snippet16"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Class/vb/BigInteger_Examples.vb" id="Snippet16"::: ]]> @@ -3542,6 +3573,7 @@ For this method matches the IEE The method defines the addition operation for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.cs" id="Snippet12"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.fs" id="Snippet12"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Class/vb/BigInteger_Examples.vb" id="Snippet12"::: Languages that do not support custom operators can call the method instead. @@ -3613,6 +3645,7 @@ For this method matches the IEE The method enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Operators/vb/Operator1.vb" id="Snippet1"::: The method performs the bitwise `And` operation on two values as if they were both in two's complement representation with virtual sign extension. @@ -3683,6 +3716,7 @@ For this method matches the IEE The method enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Operators/vb/Operator1.vb" id="Snippet2"::: The method performs the bitwise `Or` operation on two values as if they were both in two's complement representation with virtual sign extension. @@ -3742,10 +3776,12 @@ For this method matches the IEE The method defines the decrement operation for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.cs" id="Snippet17"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.fs" id="Snippet17"::: Languages that do not support custom operators can call the method instead. For example: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Operators/vb/Operator1.vb" id="Snippet3"::: Because objects are immutable, the operator creates a new object whose value is one less than the object represented by `value`. This means that repeated calls to may be expensive. @@ -3808,6 +3844,7 @@ For this method matches the IEE The method defines the division operation for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.cs" id="Snippet13"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.fs" id="Snippet13"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Class/vb/BigInteger_Examples.vb" id="Snippet13"::: Languages that do not support custom operators and operator overloading can call the method instead. @@ -3818,6 +3855,7 @@ For this method matches the IEE The following example creates an array of values. It then uses each element as the quotient in a division operation that uses the method, the division operator (/), and the method. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/Divide/Divide1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/Divide/Divide1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Divide/vb/Divide1.vb" id="Snippet1"::: ]]> @@ -3887,6 +3925,7 @@ For this method matches the IEE The method defines the equality comparison operation for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.cs" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Operators/vb/Operator1.vb" id="Snippet4"::: Languages that do not support custom operators can call the instance method instead. @@ -3948,6 +3987,7 @@ For this method matches the IEE The method defines the equality comparison operation for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.cs" id="Snippet5"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.fs" id="Snippet5"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Operators/vb/Operator1.vb" id="Snippet5"::: Languages that do not support custom operators can call the instance method instead. @@ -4013,6 +4053,7 @@ For this method matches the IEE The method defines the operation of the equality operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.cs" id="Snippet19"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.fs" id="Snippet19"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Class/vb/BigInteger_Examples.vb" id="Snippet19"::: Languages that do not support custom operators can call the instance method instead. @@ -4079,6 +4120,7 @@ For this method matches the IEE The method defines the equality comparison operation for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.cs" id="Snippet6"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.fs" id="Snippet6"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Operators/vb/Operator1.vb" id="Snippet6"::: Languages that do not support custom operators can call the instance method instead. @@ -4144,6 +4186,7 @@ For this method matches the IEE The method defines the equality comparison operation for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.cs" id="Snippet7"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.fs" id="Snippet7"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Operators/vb/Operator1.vb" id="Snippet7"::: Languages that do not support custom operators can call the instance method instead. @@ -4215,6 +4258,7 @@ For this method matches the IEE The method enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.cs" id="Snippet8"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.fs" id="Snippet8"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Operators/vb/Operator1.vb" id="Snippet8"::: The method performs the bitwise exclusive `Or` operation on two values as if they were both in two's complement representation with virtual sign extension. @@ -4288,6 +4332,7 @@ For this method matches the IEE The following example converts the individual elements in an array of values to objects, and then displays the result of each conversion. Note that any fractional part of a value is truncated during the conversion. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_Explicit/Explicit1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_Explicit/Explicit1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Explicit/vb/Explicit1.vb" id="Snippet1"::: ]]> @@ -4349,6 +4394,7 @@ For this method matches the IEE The following example converts the individual elements in an array of values to objects, and then displays the result of each conversion. Note that any fractional part of a value is truncated during the conversion. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_Explicit/Explicit1.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_Explicit/Explicit1.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Explicit/vb/Explicit1.vb" id="Snippet2"::: ]]> @@ -4443,6 +4489,7 @@ For this method matches the IEE The following example illustrates the conversion of to values. It also handles an that is thrown because the value is outside the range of the data type. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_Explicit/System.Numeric.BigInteger.Explicit.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_Explicit/System.Numeric.BigInteger.Explicit.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Explicit/vb/System.Numeric.BigInteger.Explicit.vb" id="Snippet1"::: ]]> @@ -4537,6 +4584,7 @@ For this method matches the IEE The following example illustrates the conversion of to values. It also handles an that is thrown because the value is outside the range of the data type. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_Explicit/System.Numeric.BigInteger.Explicit.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_Explicit/System.Numeric.BigInteger.Explicit.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Explicit/vb/System.Numeric.BigInteger.Explicit.vb" id="Snippet2"::: ]]> @@ -4596,6 +4644,7 @@ For this method matches the IEE The conversion of a to a may involve a loss of precision. In some cases, the loss of precision may cause the casting or conversion operation to succeed even if the value is outside the range of the data type. The following example provides an illustration. It assigns the maximum value of a to two variables, increments one variable by 9.999e291, and tests the two variables for equality. As expected, the call to the method shows that they are unequal. However, the conversion of the larger value back to a succeeds, although the value now exceeds . :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_Explicit/Explicit1.cs" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_Explicit/Explicit1.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Explicit/vb/Explicit1.vb" id="Snippet4"::: @@ -4604,6 +4653,7 @@ For this method matches the IEE The following example illustrates the conversion of to values. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_Explicit/System.Numeric.BigInteger.Explicit.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_Explicit/System.Numeric.BigInteger.Explicit.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Explicit/vb/System.Numeric.BigInteger.Explicit.vb" id="Snippet3"::: ]]> @@ -4730,6 +4780,7 @@ For this method matches the IEE The following example illustrates the conversion of to values. It also handles an that is thrown because the value is outside the range of the data type. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_Explicit/System.Numeric.BigInteger.Explicit.cs" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_Explicit/System.Numeric.BigInteger.Explicit.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Explicit/vb/System.Numeric.BigInteger.Explicit.vb" id="Snippet4"::: ]]> @@ -4790,6 +4841,7 @@ For this method matches the IEE The following example illustrates the conversion of to values. It also handles an that is thrown because the value is outside the range of the data type. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_Explicit/System.Numeric.BigInteger.Explicit.cs" id="Snippet5"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_Explicit/System.Numeric.BigInteger.Explicit.fs" id="Snippet5"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Explicit/vb/System.Numeric.BigInteger.Explicit.vb" id="Snippet5"::: ]]> @@ -4850,6 +4902,7 @@ For this method matches the IEE The following example illustrates the conversion of to values. It also handles an that is thrown because the value is outside the range of the data type. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_Explicit/System.Numeric.BigInteger.Explicit.cs" id="Snippet6"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_Explicit/System.Numeric.BigInteger.Explicit.fs" id="Snippet6"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Explicit/vb/System.Numeric.BigInteger.Explicit.vb" id="Snippet6"::: ]]> @@ -4952,6 +5005,7 @@ For this method matches the IEE The following example illustrates the conversion of to values. It also handles an that is thrown because the value is outside the range of the data type. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_Explicit/System.Numeric.BigInteger.Explicit.cs" id="Snippet7"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_Explicit/System.Numeric.BigInteger.Explicit.fs" id="Snippet7"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Explicit/vb/System.Numeric.BigInteger.Explicit.vb" id="Snippet7"::: ]]> @@ -5012,6 +5066,7 @@ For this method matches the IEE The conversion of a to a may involve a loss of precision. In some cases, the loss of precision may cause the casting or conversion operation to succeed even if the value is outside the range of the data type. The following example provides an illustration. It assigns the maximum value of a to two variables, increments one variable by 9.999e291, and tests the two variables for equality. As expected, the call to the method shows that they are unequal. However, the conversion of the larger value back to a succeeds, although the value now exceeds . :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_Explicit/Explicit1.cs" id="Snippet5"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_Explicit/Explicit1.fs" id="Snippet5"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Explicit/vb/Explicit1.vb" id="Snippet5"::: @@ -5020,6 +5075,7 @@ For this method matches the IEE The following example illustrates the conversion of to values. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_Explicit/System.Numeric.BigInteger.Explicit.cs" id="Snippet8"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_Explicit/System.Numeric.BigInteger.Explicit.fs" id="Snippet8"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Explicit/vb/System.Numeric.BigInteger.Explicit.vb" id="Snippet8"::: ]]> @@ -5126,6 +5182,7 @@ For this method matches the IEE The following example illustrates the conversion of to values. It also handles an that is thrown because the value is outside the range of the data type. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_Explicit/System.Numeric.BigInteger.Explicit.cs" id="Snippet9"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_Explicit/System.Numeric.BigInteger.Explicit.fs" id="Snippet9"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Explicit/vb/System.Numeric.BigInteger.Explicit.vb" id="Snippet9"::: ]]> @@ -5195,6 +5252,7 @@ For this method matches the IEE The following example illustrates the conversion of to values. It also handles an that is thrown because the value is outside the range of the data type. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_Explicit/System.Numeric.BigInteger.Explicit.cs" id="Snippet10"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_Explicit/System.Numeric.BigInteger.Explicit.fs" id="Snippet10"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Explicit/vb/System.Numeric.BigInteger.Explicit.vb" id="Snippet10"::: ]]> @@ -5264,6 +5322,7 @@ For this method matches the IEE The following example illustrates the conversion of to values. It also handles an that is thrown because the value is outside the range of the data type. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_Explicit/System.Numeric.BigInteger.Explicit.cs" id="Snippet11"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_Explicit/System.Numeric.BigInteger.Explicit.fs" id="Snippet11"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Explicit/vb/System.Numeric.BigInteger.Explicit.vb" id="Snippet11"::: ]]> @@ -5402,6 +5461,7 @@ For this method matches the IEE The following example converts the individual elements in an array of values to objects, and then displays the result of each conversion. Note that any fractional part of a value is truncated during the conversion. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_Explicit/Explicit1.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_Explicit/Explicit1.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Explicit/vb/Explicit1.vb" id="Snippet3"::: ]]> @@ -5470,6 +5530,7 @@ For this method matches the IEE The method defines the operation of the greater than operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.cs" id="Snippet9"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.fs" id="Snippet9"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Operators/vb/Operator1.vb" id="Snippet9"::: Languages that do not support custom operators can call the instance method instead. Some languages can also call the method directly, as the following example shows. @@ -5533,6 +5594,7 @@ For this method matches the IEE The method defines the operation of the greater than operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.cs" id="Snippet11"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.fs" id="Snippet11"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Operators/vb/Operator1.vb" id="Snippet11"::: Languages that do not support custom operators can call the method instead. Some languages can also call the method directly, as the following example shows. @@ -5600,6 +5662,7 @@ For this method matches the IEE The method defines the operation of the greater than operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.cs" id="Snippet20"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.fs" id="Snippet20"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Class/vb/BigInteger_Examples.vb" id="Snippet20"::: Languages that do not support custom operators can call the method instead. They can also call the method directly, as the following example shows. @@ -5667,6 +5730,7 @@ For this method matches the IEE The method defines the operation of the greater than operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.cs" id="Snippet13"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.fs" id="Snippet13"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Operators/vb/Operator1.vb" id="Snippet13"::: Languages that do not support custom operators can call the method instead. Some languages can also call the method directly, as the following example shows. @@ -5733,6 +5797,7 @@ For this method matches the IEE The method defines the operation of the greater than operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.cs" id="Snippet15"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.fs" id="Snippet15"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Operators/vb/Operator1.vb" id="Snippet15"::: Languages that do not support custom operators can call the method instead. Some languages can also call the method directly, as the following example shows. @@ -5804,6 +5869,7 @@ For this method matches the IEE The method defines the operation of the greater than or equal to operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.cs" id="Snippet17"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.fs" id="Snippet17"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Operators/vb/Operator1.vb" id="Snippet17"::: Languages that do not support custom operators can call the method instead. Some languages can also call the method directly, as the following example shows. @@ -5867,6 +5933,7 @@ For this method matches the IEE The method defines the operation of the greater than or equal to operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.cs" id="Snippet19"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.fs" id="Snippet19"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Operators/vb/Operator1.vb" id="Snippet19"::: Languages that do not support custom operators can call the method instead. Some languages can also call the method directly, as the following example shows. @@ -5934,6 +6001,7 @@ For this method matches the IEE The method defines the operation of the greater than or equal to operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.cs" id="Snippet22"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.fs" id="Snippet22"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Class/vb/BigInteger_Examples.vb" id="Snippet22"::: Languages that do not support custom operators can call the method instead. Some languages can also call the method directly, as the following example shows. @@ -6001,6 +6069,7 @@ For this method matches the IEE The method defines the operation of the greater than or equal to operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.cs" id="Snippet21"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.fs" id="Snippet21"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Operators/vb/Operator1.vb" id="Snippet21"::: Languages that do not support custom operators can call the method instead. Some languages can also call the method directly, as the following example shows. @@ -6068,6 +6137,7 @@ For this method matches the IEE The method defines the operation of the greater than or equal to operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.cs" id="Snippet23"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.fs" id="Snippet23"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Operators/vb/Operator1.vb" id="Snippet23"::: Languages that do not support custom operators can call the method instead. Some languages can also call the method directly, as the following example shows. @@ -6140,6 +6210,7 @@ For this method matches the IEE The overloads of the method define the types to which or from which a compiler can automatically convert a value without an explicit casting operator (in C#) or a call to a conversion function (in Visual Basic). They are widening conversions that do not involve data loss and do not throw an . This overload lets the compiler handle conversions from a value to a value, as the following example shows. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_Implicit/Implicit1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_Implicit/Implicit1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Implicit/vb/Implicit1.vb" id="Snippet1"::: ]]> @@ -6263,6 +6334,7 @@ For this method matches the IEE The overloads of the method define the types to which or from which a compiler can automatically convert a value without an explicit casting operator (in C#) or a call to a conversion function (in Visual Basic). They are widening conversions that do not involve data loss and do not throw an . This overload lets the compiler handle conversions from a value to a value, as the following example shows. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_Implicit/Implicit1.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_Implicit/Implicit1.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Implicit/vb/Implicit1.vb" id="Snippet2"::: ]]> @@ -6318,6 +6390,7 @@ For this method matches the IEE The overloads of the method define the types to which or from which a compiler can automatically convert a value without an explicit casting operator (in C#) or a call to a conversion function (in Visual Basic). They are widening conversions that do not involve data loss and do not throw an . This overload lets the compiler handle conversions from a value to a value, as the following example shows. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_Implicit/Implicit1.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_Implicit/Implicit1.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Implicit/vb/Implicit1.vb" id="Snippet3"::: ]]> @@ -6373,6 +6446,7 @@ For this method matches the IEE The overloads of the method define the types to which or from which a compiler can automatically convert a value without an explicit casting operator (in C#) or a call to a conversion function (in Visual Basic). They are widening conversions that do not involve data loss and do not throw an . This overload lets the compiler handle conversions from a value to a value, as the following example shows. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_Implicit/Implicit1.cs" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_Implicit/Implicit1.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Implicit/vb/Implicit1.vb" id="Snippet4"::: ]]> @@ -6470,6 +6544,7 @@ For this method matches the IEE The overloads of the method define the types to which or from which a compiler can automatically convert a value without an explicit casting operator (in C#) or a call to a conversion function (in Visual Basic). They are widening conversions that do not involve data loss and do not throw an . This overload lets the compiler handle conversions from a value to a value, as the following example shows. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_Implicit/Implicit1.cs" id="Snippet5"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_Implicit/Implicit1.fs" id="Snippet5"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Implicit/vb/Implicit1.vb" id="Snippet5"::: ]]> @@ -6574,6 +6649,7 @@ For this method matches the IEE The overloads of the method define the types to which or from which a compiler can automatically convert a value without an explicit casting operator (in C#) or a call to a conversion function (in Visual Basic). They are widening conversions that do not involve data loss and do not throw an . This overload lets the compiler handle conversions from a value to a value, as the following example shows. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_Implicit/Implicit1.cs" id="Snippet6"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_Implicit/Implicit1.fs" id="Snippet6"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Implicit/vb/Implicit1.vb" id="Snippet6"::: ]]> @@ -6638,6 +6714,7 @@ For this method matches the IEE The overloads of the method define the types to which or from which a compiler can automatically convert a value without an explicit casting operator (in C#) or a call to a conversion function (in Visual Basic). They are widening conversions that do not involve data loss and do not throw an . This overload lets the compiler handle conversions from a value to a value, as the following example shows. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_Implicit/Implicit1.cs" id="Snippet7"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_Implicit/Implicit1.fs" id="Snippet7"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Implicit/vb/Implicit1.vb" id="Snippet7"::: ]]> @@ -6702,6 +6779,7 @@ For this method matches the IEE The overloads of the method define the types to which or from which a compiler can automatically convert a value without an explicit casting operator (in C#) or a call to a conversion function (in Visual Basic). They are widening conversions that do not involve data loss and do not throw an . This overload lets the compiler handle conversions from a value to a value, as the following example shows. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_Implicit/Implicit1.cs" id="Snippet8"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_Implicit/Implicit1.fs" id="Snippet8"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Implicit/vb/Implicit1.vb" id="Snippet8"::: ]]> @@ -6800,6 +6878,7 @@ For this method matches the IEE The method defines the increment operation for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.cs" id="Snippet24"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.fs" id="Snippet24"::: Some languages (such as Visual Basic) that lack an increment operator or do not support operator overloading can call the method directly, as the following example shows. @@ -6872,6 +6951,7 @@ For this method matches the IEE The method defines the operation of the inequality operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.cs" id="Snippet25"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.fs" id="Snippet25"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Operators/vb/Operator1.vb" id="Snippet25"::: Languages that do not support custom operators can test for inequality by using one of the following techniques: @@ -6937,6 +7017,7 @@ For this method matches the IEE The method defines the operation of the inequality operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.cs" id="Snippet26"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.fs" id="Snippet26"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Operators/vb/Operator1.vb" id="Snippet26"::: Languages that do not support custom operators can test for inequality by using one of the following techniques: @@ -7006,6 +7087,7 @@ For this method matches the IEE The method defines the operation of the inequality operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.cs" id="Snippet26"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.fs" id="Snippet26"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Class/vb/BigInteger_Examples.vb" id="Snippet26"::: Languages that do not support custom operators can test for inequality by using one of the following techniques: @@ -7075,6 +7157,7 @@ For this method matches the IEE The method defines the operation of the inequality operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.cs" id="Snippet27"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.fs" id="Snippet27"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Operators/vb/Operator1.vb" id="Snippet27"::: Languages that do not support custom operators can test for inequality by using one of the following techniques: @@ -7144,6 +7227,7 @@ For this method matches the IEE The method defines the operation of the inequality operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.cs" id="Snippet28"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.fs" id="Snippet28"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Operators/vb/Operator1.vb" id="Snippet28"::: Languages that do not support custom operators can test for inequality by using one of the following techniques: @@ -7210,6 +7294,7 @@ For this method matches the IEE The method defines the operation of the bitwise left-shift operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.cs" id="Snippet29"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.fs" id="Snippet29"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Operators/vb/Operator1.vb" id="Snippet29"::: > [!NOTE] @@ -7218,6 +7303,7 @@ For this method matches the IEE Languages that do not support custom operators can perform a bitwise left-shift operation by multiplying `value` by `BigInteger.Pow(2, shift)`. The following example shows that the results are identical to the results of using this operator. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.cs" id="Snippet30"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.fs" id="Snippet30"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Operators/vb/Operator1.vb" id="Snippet30"::: ]]> @@ -7285,6 +7371,7 @@ For this method matches the IEE The method defines the operation of the less than operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.cs" id="Snippet31"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.fs" id="Snippet31"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Operators/vb/Operator1.vb" id="Snippet31"::: Languages that do not support custom operators can call the method instead. Some languages can also call the method directly, as the following example shows. @@ -7348,6 +7435,7 @@ For this method matches the IEE The method defines the operation of the less than operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.cs" id="Snippet33"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.fs" id="Snippet33"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Operators/vb/Operator1.vb" id="Snippet33"::: Languages that do not support custom operators can call the method instead. Some languages can also call the method directly, as the following example shows. @@ -7415,6 +7503,7 @@ For this method matches the IEE The method defines the operation of the less than operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.cs" id="Snippet27"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.fs" id="Snippet27"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Class/vb/BigInteger_Examples.vb" id="Snippet27"::: Languages that do not support custom operators can call the method instead. Some languages can also call the method directly, as the following example shows. @@ -7482,6 +7571,7 @@ For this method matches the IEE The method defines the operation of the less than operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.cs" id="Snippet35"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.fs" id="Snippet35"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Operators/vb/Operator1.vb" id="Snippet35"::: Languages that do not support custom operators can call the method instead. They can also call the method directly, as the following example shows. @@ -7549,6 +7639,7 @@ For this method matches the IEE The method defines the operation of the less than operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.cs" id="Snippet37"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.fs" id="Snippet37"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Operators/vb/Operator1.vb" id="Snippet37"::: Languages that do not support custom operators can call the method instead. They can also call the method directly, as the following example shows. @@ -7620,6 +7711,7 @@ For this method matches the IEE The method defines the operation of the less than or equal to operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.cs" id="Snippet39"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.fs" id="Snippet39"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Operators/vb/Operator1.vb" id="Snippet39"::: Languages that do not support custom operators can call the method instead. They can also call the method directly, as the following example shows. @@ -7683,6 +7775,7 @@ For this method matches the IEE The method defines the operation of the less than or equal to operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.cs" id="Snippet41"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.fs" id="Snippet41"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Operators/vb/Operator1.vb" id="Snippet41"::: Languages that do not support custom operators can call the method instead. They can also call the method directly, as the following example shows. @@ -7750,6 +7843,7 @@ For this method matches the IEE The method defines the operation of the less than or equal to operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.cs" id="Snippet29"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.fs" id="Snippet29"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Class/vb/BigInteger_Examples.vb" id="Snippet29"::: Languages that do not support custom operators can call the method instead. They can also call the method directly, as the following example shows. @@ -7817,6 +7911,7 @@ For this method matches the IEE The method defines the operation of the less than or equal to operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.cs" id="Snippet43"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.fs" id="Snippet43"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Operators/vb/Operator1.vb" id="Snippet43"::: Languages that do not support custom operators can call the method instead. They can also call the method directly, as the following example shows. @@ -7884,6 +7979,7 @@ For this method matches the IEE The method defines the operation of the less than or equal to operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.cs" id="Snippet45"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/Operator1.fs" id="Snippet45"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Operators/vb/Operator1.vb" id="Snippet45"::: Languages that do not support custom operators can call the method instead. They can also call the method directly, as the following example shows. @@ -7948,6 +8044,7 @@ For this method matches the IEE The method defines the operation of the modulus operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.cs" id="Snippet31"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.fs" id="Snippet31"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Class/vb/BigInteger_Examples.vb" id="Snippet31"::: Languages that do not support custom operators can call the method instead. @@ -8015,6 +8112,7 @@ For this method matches the IEE The method defines the operation of the multiplication operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.cs" id="Snippet11"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.fs" id="Snippet11"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Class/vb/BigInteger_Examples.vb" id="Snippet11"::: The equivalent method for this operator is .]]> @@ -8073,6 +8171,7 @@ For this method matches the IEE The method defines the operation of the bitwise one's complement operator for values. The bitwise one's complement operator reverses each bit in a numeric value. That is, bits in `value` that are 0 are set to 1 in the result, and bits that are 1 are set to 0 in the result. The method enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_OnesComplement/OnesComplement1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_OnesComplement/OnesComplement1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.OnesComplement/vb/OnesComplement1.vb" id="Snippet1"::: Languages that do not support custom operators may be able to call the method directly to perform a bitwise one's complement operation. For example: @@ -8136,11 +8235,13 @@ For this method matches the IEE The method defines the operation of the bitwise right-shift operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_BitwiseAnd/RightShift1.cs" id="Snippet47"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/RightShift1.fs" id="Snippet47"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Operators/vb/Operator1.vb" id="Snippet47"::: Languages that do not support custom operators can perform a bitwise right-shift operation by dividing `value` by `BigInteger.Pow(2, shift)` and subtracting 1 times `shift` for negative values. The following example shows that the results are identical to the results of using this operator. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/op_BitwiseAnd/RightShift1.cs" id="Snippet48"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/op_BitwiseAnd/RightShift1.fs" id="Snippet48"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Operators/vb/Operator1.vb" id="Snippet48"::: If `shift` is greater than or equal to the number of bits in a positive value, the result of the right-shift operation is . If `shift` is greater than the number of bits in a negative value, the result of the right-shift operation is . @@ -8203,6 +8304,7 @@ For this method matches the IEE The method defines the operation of the subtraction operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.cs" id="Snippet14"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.fs" id="Snippet14"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Class/vb/BigInteger_Examples.vb" id="Snippet14"::: Languages that do not support custom operators can call the method instead. @@ -8268,6 +8370,7 @@ For this method matches the IEE The following example illustrates three different ways to negate the value of a object. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.cs" id="Snippet16"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.fs" id="Snippet16"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Class/vb/BigInteger_Examples.vb" id="Snippet16"::: ]]> @@ -8461,6 +8564,7 @@ This operation performs an unsigned (otherwise known as a logical) right shift o The following example uses the method to instantiate two objects. It multiplies each object by another number and then calls the method to determine the relationship between the two values. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/Parse/Parse1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/Parse/Parse1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Parse/vb/Parse1.vb" id="Snippet1"::: ]]> @@ -8626,6 +8730,7 @@ This operation performs an unsigned (otherwise known as a logical) right shift o If `value` is a hexadecimal string, the method interprets `value` as a negative number stored by using two's complement representation if its first two hexadecimal digits are greater than or equal to `0x80`. In other words, the method interprets the highest-order bit of the first byte in `value` as the sign bit. To make sure that a hexadecimal string is correctly interpreted as a positive number, the first digit in `value` must have a value of zero. For example, the method interprets `0x80` as a negative value, but it interprets either `0x080` or `0x0080` as a positive value. The following example illustrates the difference between hexadecimal strings that represent negative and positive values. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/Parse/ParseHex1.cs" interactive="try-dotnet" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/Parse/ParseHex1.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Parse/vb/ParseHex1.vb" id="Snippet3"::: The `value` parameter is parsed by using the formatting information in a object that is initialized for the current system culture. To specify the culture whose formatting information is used for the parse operation, call the overload. @@ -8636,6 +8741,7 @@ This operation performs an unsigned (otherwise known as a logical) right shift o The following example illustrates calls to the method with several possible values for the `style` parameter. It illustrates how to interpret a string as a hexadecimal value, and how to disallow spaces and sign symbols. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/Parse/System.Numeric.BigInteger.Parse.cs" id="Snippet5"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/Parse/System.Numeric.BigInteger.Parse.fs" id="Snippet5"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Parse/vb/System.Numeric.BigInteger.Parse.vb" id="Snippet5"::: ]]> @@ -8753,16 +8859,19 @@ This operation performs an unsigned (otherwise known as a logical) right shift o The first example defines a class that implements and uses the method to return the object that provides formatting information. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/Parse/System.Numeric.BigInteger.Parse.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/Parse/System.Numeric.BigInteger.Parse.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Parse/vb/System.Numeric.BigInteger.Parse.vb" id="Snippet2"::: A object can then be instantiated with the following code: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/Parse/System.Numeric.BigInteger.Parse.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/Parse/System.Numeric.BigInteger.Parse.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Parse/vb/System.Numeric.BigInteger.Parse.vb" id="Snippet3"::: The second example is more straightforward. It passes the object that provides formatting information to the `provider` parameter. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/Parse/System.Numeric.BigInteger.Parse.cs" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/Parse/System.Numeric.BigInteger.Parse.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Parse/vb/System.Numeric.BigInteger.Parse.vb" id="Snippet4"::: ]]> @@ -9023,6 +9132,7 @@ If `provider` is `null`, the object If `value` is a hexadecimal string, the method interprets `value` as a negative number stored by using two's complement representation if its first two hexadecimal digits are greater than or equal to `0x80`. In other words, the method interprets the highest-order bit of the first byte in `value` as the sign bit. To make sure that a hexadecimal string is correctly interpreted as a positive number, the first digit in `value` must have a value of zero. For example, the method interprets `0x80` as a negative value, but it interprets either `0x080` or `0x0080` as a positive value. The following example illustrates the difference between hexadecimal strings that represent negative and positive values. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/Parse/ParseHex1.cs" interactive="try-dotnet" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/Parse/ParseHex1.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Parse/vb/ParseHex1.vb" id="Snippet3"::: The `provider` parameter is an implementation. Its method returns a object that provides culture-specific information about the format of `value`. Typically, `provider` can be any one of the following: @@ -9041,11 +9151,13 @@ If `provider` is `null`, the object The following example makes several calls to the method using various combinations of values for the `style` and `provider` parameters. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/Parse/Parse1.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/Parse/Parse1.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Parse/vb/Parse1.vb" id="Snippet2"::: A number of the individual calls to the method pass an instance of the following `BigIntegerFormatProvider` class, which defines a tilde (~) as the negative sign. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/Parse/Parse1.cs" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/Parse/Parse1.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Parse/vb/Parse1.vb" id="Snippet4"::: ]]> @@ -9156,6 +9268,7 @@ If `provider` is `null`, the object The following example illustrates exponentiation using a value and an exponent whose value ranges from 0 to 10. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.cs" id="Snippet32"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/GreatestCommonDivisor/BigInteger_Examples.fs" id="Snippet32"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.Class/vb/BigInteger_Examples.vb" id="Snippet32"::: ]]> @@ -9228,6 +9341,7 @@ If `provider` is `null`, the object The following example compares the remainder from the method with the remainder returned by the method to establish that the two methods calculate identical remainders. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/Remainder/Remainder1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/Remainder/Remainder1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.Remainder/vb/Remainder1.vb" id="Snippet1"::: ]]> @@ -9437,6 +9551,7 @@ If `provider` is `null`, the object The method is a useful substitute for the subtraction operator when instantiating a variable by assigning it the difference that results from subtraction, as shown in the following example. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/Add/Multiply1.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/Add/Multiply1.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.OperationMethods/vb/Multiply1.vb" id="Snippet3"::: ]]> @@ -9492,6 +9607,7 @@ If `provider` is `null`, the object The following example calls the method to compare a value with each element in an object array: :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/CompareTo/Example2.cs" id="Snippet4"::: +:::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/CompareTo/Example2.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.CompareTo/vb/Example2.vb" id="Snippet4"::: ]]> @@ -10954,6 +11070,7 @@ The following example calls the values are represented in byte arrays. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/ToByteArray/ToByteArray1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/ToByteArray/ToByteArray1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.ToByteArray/vb/ToByteArray1.vb" id="Snippet1"::: ]]> @@ -11096,6 +11213,7 @@ The integer value `33022` can be exported in four different arrays: 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.Numerics/BigInteger/ToString/ToString1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/ToString/ToString1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.ToString/vb/ToString1.vb" id="Snippet1"::: ]]> @@ -11186,6 +11304,7 @@ The integer value `33022` can be exported in four different arrays: The following example instantiates a custom object that defines the tilde (~) as a negative sign. The method then uses the custom object to display a negative value. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/ToString/System.Numeric.BigInteger.ToString.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/ToString/System.Numeric.BigInteger.ToString.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.ToString/vb/System.Numeric.BigInteger.ToString.vb" id="Snippet1"::: ]]> @@ -11278,6 +11397,7 @@ The integer value `33022` can be exported in four different arrays: The following example initializes a value and displays it by using each standard format string and some custom format strings. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/ToString/ToString1.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/ToString/ToString1.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.ToString/vb/ToString1.vb" id="Snippet3"::: ]]> @@ -11383,6 +11503,7 @@ The integer value `33022` can be exported in four different arrays: The following example initializes a value, and displays it to the console using a standard format string and a object that defines the tilde (~) as a negative sign. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/ToString/ToString1.cs" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/ToString/ToString1.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.ToString/vb/ToString1.vb" id="Snippet4"::: ]]> @@ -11638,6 +11759,7 @@ The integer value `33022` can be exported in four different arrays: The following example uses the method to instantiate two objects. If the conversions succeed, it multiplies each object by another number and then calls the method to determine the relationship between the two objects. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/TryParse/System.Numeric.BigInteger.TryParse.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/TryParse/System.Numeric.BigInteger.TryParse.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numeric.BigInteger.TryParse/vb/System.Numeric.BigInteger.TryParse.vb" id="Snippet1"::: ]]> @@ -11994,6 +12116,7 @@ If `provider` is `null`, the object If `value` is a hexadecimal string, the method interprets `value` as a negative number stored by using two's complement representation if its first two hexadecimal digits are greater than or equal to `0x80`. In other words, the method interprets the highest-order bit of the first byte in `value` as the sign bit. To make sure that a hexadecimal string is correctly interpreted as a positive number, the first digit in `value` must have a value of zero. For example, the method interprets `0x80` as a negative value, but it interprets either `0x080` or `0x0080` as a positive value. The following example illustrates the difference between hexadecimal strings that represent negative and positive values. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/TryParse/TryParseHex1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/TryParse/TryParseHex1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.TryParse/vb/TryParseHex1.vb" id="Snippet1"::: The `provider` parameter is an implementation. Its method returns a object that provides culture-specific information about the format of `value`. The `provider` parameter can be any one of the following: @@ -12012,11 +12135,13 @@ If `provider` is `null`, the object The following example makes some calls to the method using various combinations of values for the `style` and `provider` parameters. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/TryParse/TryParse1.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/TryParse/TryParse1.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.TryParse/vb/TryParse1.vb" id="Snippet2"::: A number of the individual calls to the method pass an instance of the following `BigIntegerFormatProvider` class, which defines a tilde (~) as the negative sign. :::code language="csharp" source="~/snippets/csharp/System.Numerics/BigInteger/TryParse/TryParse1.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/BigInteger/TryParse/TryParse1.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Numerics.BigInteger.TryParse/vb/TryParse1.vb" id="Snippet3"::: ]]> From 497baea73c31ad56203a2d1bbb96d4ce17867fec Mon Sep 17 00:00:00 2001 From: Albert Du <52804499+albert-du@users.noreply.github.com> Date: Mon, 24 Jun 2024 07:23:48 -0700 Subject: [PATCH 04/10] F# snippets for Complex (#10052) --- .../System.Numerics/Complex/.ctor/ctor1.fs | 16 +++ .../System.Numerics/Complex/.ctor/fs.fsproj | 10 ++ .../System.Numerics/Complex/Abs/abs1.fs | 10 ++ .../System.Numerics/Complex/Abs/fs.fsproj | 10 ++ .../System.Numerics/Complex/Acos/acos1.fs | 14 +++ .../System.Numerics/Complex/Acos/fs.fsproj | 10 ++ .../System.Numerics/Complex/Add/add1.fs | 20 ++++ .../System.Numerics/Complex/Add/add2.fs | 20 ++++ .../System.Numerics/Complex/Add/add3.fs | 9 ++ .../System.Numerics/Complex/Add/fs.fsproj | 12 ++ .../System.Numerics/Complex/Asin/asin1.fs | 17 +++ .../System.Numerics/Complex/Asin/fs.fsproj | 10 ++ .../System.Numerics/Complex/Atan/atan1.fs | 17 +++ .../System.Numerics/Complex/Atan/fs.fsproj | 10 ++ .../Complex/Conjugate/conjugate1.fs | 16 +++ .../Complex/Conjugate/fs.fsproj | 10 ++ .../System.Numerics/Complex/Divide/divide1.fs | 18 +++ .../System.Numerics/Complex/Divide/divide2.fs | 9 ++ .../System.Numerics/Complex/Divide/fs.fsproj | 11 ++ .../Complex/Equals/eqoperator1.fs | 10 ++ .../System.Numerics/Complex/Equals/equals1.fs | 23 ++++ .../System.Numerics/Complex/Equals/equals3.fs | 7 ++ .../System.Numerics/Complex/Equals/equals4.fs | 10 ++ .../System.Numerics/Complex/Equals/fs.fsproj | 15 +++ .../Complex/Equals/precision1.fs | 31 +++++ .../Complex/Equals/precision2.fs | 15 +++ .../System.Numerics/Complex/Exp/fs.fsproj | 10 ++ .../System.Numerics/Complex/Exp/log1.fs | 20 ++++ .../Complex/FromPolarCoordinates/fs.fsproj | 10 ++ .../Complex/FromPolarCoordinates/phase1.fs | 17 +++ .../Complex/Imaginary/fs.fsproj | 10 ++ .../Complex/Imaginary/real1.fs | 12 ++ .../Complex/ImaginaryOne/fs.fsproj | 10 ++ .../Complex/ImaginaryOne/imaginaryone1.fs | 13 +++ .../Complex/Multiply/fs.fsproj | 11 ++ .../Complex/Multiply/multiply1.fs | 14 +++ .../Complex/Multiply/multiply2.fs | 9 ++ .../System.Numerics/Complex/Negate/fs.fsproj | 11 ++ .../System.Numerics/Complex/Negate/negate1.fs | 15 +++ .../System.Numerics/Complex/Negate/negate2.fs | 8 ++ .../System.Numerics/Complex/One/fs.fsproj | 10 ++ .../System.Numerics/Complex/One/one1.fs | 13 +++ .../System.Numerics/Complex/Pow/fs.fsproj | 10 ++ .../System.Numerics/Complex/Pow/pow1.fs | 21 ++++ .../Complex/Reciprocal/fs.fsproj | 10 ++ .../Complex/Reciprocal/reciprocal1.fs | 15 +++ .../Complex/ToString/fs.fsproj | 13 +++ .../Complex/ToString/tostring1.fs | 19 +++ .../Complex/ToString/tostring2.fs | 24 ++++ .../Complex/ToString/tostring3.fs | 34 ++++++ .../Complex/ToString/tostring4.fs | 39 +++++++ .../System.Numerics/Complex/Zero/fs.fsproj | 10 ++ .../System.Numerics/Complex/Zero/zero1.fs | 13 +++ .../Complex/op_Explicit/explicit1.fs | 38 ++++++ .../Complex/op_Explicit/fs.fsproj | 10 ++ .../Complex/op_Implicit/fs.fsproj | 10 ++ .../Complex/op_Implicit/implicit1.fs | 110 ++++++++++++++++++ .../Complex/op_Inequality/fs.fsproj | 10 ++ .../Complex/op_Inequality/inequality1.fs | 9 ++ .../Complex/op_Subtraction/fs.fsproj | 11 ++ .../Complex/op_Subtraction/subtract1.fs | 20 ++++ .../Complex/op_Subtraction/subtract2.fs | 9 ++ xml/System.Numerics/Complex.xml | 58 +++++++++ 63 files changed, 1046 insertions(+) create mode 100644 snippets/fsharp/System.Numerics/Complex/.ctor/ctor1.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/.ctor/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/Complex/Abs/abs1.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/Abs/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/Complex/Acos/acos1.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/Acos/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/Complex/Add/add1.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/Add/add2.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/Add/add3.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/Add/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/Complex/Asin/asin1.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/Asin/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/Complex/Atan/atan1.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/Atan/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/Complex/Conjugate/conjugate1.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/Conjugate/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/Complex/Divide/divide1.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/Divide/divide2.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/Divide/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/Complex/Equals/eqoperator1.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/Equals/equals1.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/Equals/equals3.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/Equals/equals4.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/Equals/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/Complex/Equals/precision1.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/Equals/precision2.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/Exp/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/Complex/Exp/log1.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/FromPolarCoordinates/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/Complex/FromPolarCoordinates/phase1.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/Imaginary/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/Complex/Imaginary/real1.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/ImaginaryOne/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/Complex/ImaginaryOne/imaginaryone1.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/Multiply/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/Complex/Multiply/multiply1.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/Multiply/multiply2.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/Negate/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/Complex/Negate/negate1.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/Negate/negate2.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/One/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/Complex/One/one1.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/Pow/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/Complex/Pow/pow1.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/Reciprocal/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/Complex/Reciprocal/reciprocal1.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/ToString/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/Complex/ToString/tostring1.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/ToString/tostring2.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/ToString/tostring3.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/ToString/tostring4.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/Zero/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/Complex/Zero/zero1.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/op_Explicit/explicit1.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/op_Explicit/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/Complex/op_Implicit/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/Complex/op_Implicit/implicit1.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/op_Inequality/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/Complex/op_Inequality/inequality1.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/op_Subtraction/fs.fsproj create mode 100644 snippets/fsharp/System.Numerics/Complex/op_Subtraction/subtract1.fs create mode 100644 snippets/fsharp/System.Numerics/Complex/op_Subtraction/subtract2.fs diff --git a/snippets/fsharp/System.Numerics/Complex/.ctor/ctor1.fs b/snippets/fsharp/System.Numerics/Complex/.ctor/ctor1.fs new file mode 100644 index 00000000000..7d245ba783a --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/.ctor/ctor1.fs @@ -0,0 +1,16 @@ +// +open System.Numerics + +let complex1 = Complex(17.34, 12.87) +let complex2 = Complex(8.76, 5.19) + +printfn $"{complex1} + {complex2} = {complex1 + complex2}" +printfn $"{complex1} - {complex2} = {complex1 - complex2}" +printfn $"{complex1} * {complex2} = {complex1 * complex2}" +printfn $"{complex1} / {complex2} = {complex1 / complex2}" +// The example displays the following output: +// (17.34, 12.87) + (8.76, 5.19) = (26.1, 18.06) +// (17.34, 12.87) - (8.76, 5.19) = (8.58, 7.68) +// (17.34, 12.87) * (8.76, 5.19) = (85.1031, 202.7358) +// (17.34, 12.87) / (8.76, 5.19) = (2.10944241403558, 0.219405693054265) +// diff --git a/snippets/fsharp/System.Numerics/Complex/.ctor/fs.fsproj b/snippets/fsharp/System.Numerics/Complex/.ctor/fs.fsproj new file mode 100644 index 00000000000..8a7745aae4c --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/.ctor/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/Complex/Abs/abs1.fs b/snippets/fsharp/System.Numerics/Complex/Abs/abs1.fs new file mode 100644 index 00000000000..09281b0aaa3 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Abs/abs1.fs @@ -0,0 +1,10 @@ +// +open System.Numerics + +let complex1 = Complex(2., 3.) +printfn $"|{complex1}| = {Complex.Abs complex1:N2}" +printfn $"Equal to Magnitude: {Complex.Abs(complex1).Equals complex1.Magnitude}" +// The example displays the following output: +// |(2, 3)| = 3.61 +// Equal to Magnitude: True +// diff --git a/snippets/fsharp/System.Numerics/Complex/Abs/fs.fsproj b/snippets/fsharp/System.Numerics/Complex/Abs/fs.fsproj new file mode 100644 index 00000000000..a9658fc50af --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Abs/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/Complex/Acos/acos1.fs b/snippets/fsharp/System.Numerics/Complex/Acos/acos1.fs new file mode 100644 index 00000000000..f0eadd554b8 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Acos/acos1.fs @@ -0,0 +1,14 @@ +// +open System.Numerics + +let values = + [ Complex(0.5, 2.); Complex(0.5, -2.); Complex(-0.5, 2.); Complex(-0.3, -0.8) ] + +for value in values do + printfn $"Cos(ACos({value})) = {Complex.Acos value |> Complex.Cos}" +// The example displays the following output: +// Cos(ACos((0.5, 2))) = (0.5, 2) +// Cos(ACos((0.5, -2))) = (0.5, -2) +// Cos(ACos((-0.5, 2))) = (-0.5, 2) +// Cos(ACos((-0.3, -0.8))) = (-0.3, -0.8) +// diff --git a/snippets/fsharp/System.Numerics/Complex/Acos/fs.fsproj b/snippets/fsharp/System.Numerics/Complex/Acos/fs.fsproj new file mode 100644 index 00000000000..caeca31b194 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Acos/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/Complex/Add/add1.fs b/snippets/fsharp/System.Numerics/Complex/Add/add1.fs new file mode 100644 index 00000000000..c8beccf4946 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Add/add1.fs @@ -0,0 +1,20 @@ +module add1 +// +open System.Numerics + +let values = [ Complex(12.3, -1.4); Complex(-6.2, 3.1); Complex(8.9, 1.5) ] + +for c1 in values do + for c2 in values do + printfn $"{c1} + {c2} = {Complex.Add(c1, c2)}" +// The example displays the following output: +// (12.3, -1.4) + (12.3, -1.4) = (24.6, -2.8) +// (12.3, -1.4) + (-6.2, 3.1) = (6.1, 1.7) +// (12.3, -1.4) + (8.9, 1.5) = (21.2, 0.1) +// (-6.2, 3.1) + (12.3, -1.4) = (6.1, 1.7) +// (-6.2, 3.1) + (-6.2, 3.1) = (-12.4, 6.2) +// (-6.2, 3.1) + (8.9, 1.5) = (2.7, 4.6) +// (8.9, 1.5) + (12.3, -1.4) = (21.2, 0.1) +// (8.9, 1.5) + (-6.2, 3.1) = (2.7, 4.6) +// (8.9, 1.5) + (8.9, 1.5) = (17.8, 3) +// diff --git a/snippets/fsharp/System.Numerics/Complex/Add/add2.fs b/snippets/fsharp/System.Numerics/Complex/Add/add2.fs new file mode 100644 index 00000000000..07b5b3d3f85 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Add/add2.fs @@ -0,0 +1,20 @@ +module add2 +// +open System.Numerics + +let values = [ Complex(12.3, -1.4); Complex(-6.2, 3.1); Complex(8.9, 1.5) ] + +for c1 in values do + for c2 in values do + printfn $"{c1} + {c2} = {c1 + c2}" +// The example displays the following output: +// (12.3, -1.4) + (12.3, -1.4) = (24.6, -2.8) +// (12.3, -1.4) + (-6.2, 3.1) = (6.1, 1.7) +// (12.3, -1.4) + (8.9, 1.5) = (21.2, 0.1) +// (-6.2, 3.1) + (12.3, -1.4) = (6.1, 1.7) +// (-6.2, 3.1) + (-6.2, 3.1) = (-12.4, 6.2) +// (-6.2, 3.1) + (8.9, 1.5) = (2.7, 4.6) +// (8.9, 1.5) + (12.3, -1.4) = (21.2, 0.1) +// (8.9, 1.5) + (-6.2, 3.1) = (2.7, 4.6) +// (8.9, 1.5) + (8.9, 1.5) = (17.8, 3) +// diff --git a/snippets/fsharp/System.Numerics/Complex/Add/add3.fs b/snippets/fsharp/System.Numerics/Complex/Add/add3.fs new file mode 100644 index 00000000000..e923c4f1a3a --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Add/add3.fs @@ -0,0 +1,9 @@ +module add3 + +open System.Numerics + +// +let c1 = Complex(1.2, 2.3) +let c2 = Complex(2.1, 3.2) +let c3 = c1 + c2 +// diff --git a/snippets/fsharp/System.Numerics/Complex/Add/fs.fsproj b/snippets/fsharp/System.Numerics/Complex/Add/fs.fsproj new file mode 100644 index 00000000000..3828c7512b8 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Add/fs.fsproj @@ -0,0 +1,12 @@ + + + Exe + net8.0 + + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/Complex/Asin/asin1.fs b/snippets/fsharp/System.Numerics/Complex/Asin/asin1.fs new file mode 100644 index 00000000000..cf5861e6a7a --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Asin/asin1.fs @@ -0,0 +1,17 @@ +// +open System.Numerics + +let values = + [ Complex(2.3, 1.4) + Complex(-2.3, 1.4) + Complex(-2.3, -1.4) + Complex(2.3, -1.4) ] + +for value in values do + printfn $"Sin(Asin({value})) = {Complex.Asin value |> Complex.Sin}" +// The example displays the following output: +// Sin(Asin((2.3, 1.4))) = (2.3, 1.4) +// Sin(Asin((-2.3, 1.4))) = (-2.3, 1.4) +// Sin(Asin((-2.3, -1.4))) = (-2.3, -1.4) +// Sin(Asin((2.3, -1.4))) = (2.3, -1.4) +// diff --git a/snippets/fsharp/System.Numerics/Complex/Asin/fs.fsproj b/snippets/fsharp/System.Numerics/Complex/Asin/fs.fsproj new file mode 100644 index 00000000000..9d8fe56ab3f --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Asin/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/Complex/Atan/atan1.fs b/snippets/fsharp/System.Numerics/Complex/Atan/atan1.fs new file mode 100644 index 00000000000..7ceb4a58080 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Atan/atan1.fs @@ -0,0 +1,17 @@ +// +open System.Numerics + +let values = + [ Complex(2.5, 1.5) + Complex(2.5, -1.5) + Complex(-2.5, 1.5) + Complex(-2.5, -1.5) ] + +for value in values do + printfn $"Tan(Atan({value})) = {Complex.Atan value |> Complex.Tan}" +// The example displays the following output: +// Tan(Atan((2.5, 1.5))) = (2.5, 1.5) +// Tan(Atan((2.5, -1.5))) = (2.5, -1.5) +// Tan(Atan((-2.5, 1.5))) = (-2.5, 1.5) +// Tan(Atan((-2.5, -1.5))) = (-2.5, -1.5) +// diff --git a/snippets/fsharp/System.Numerics/Complex/Atan/fs.fsproj b/snippets/fsharp/System.Numerics/Complex/Atan/fs.fsproj new file mode 100644 index 00000000000..f96aca08d13 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Atan/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/Complex/Conjugate/conjugate1.fs b/snippets/fsharp/System.Numerics/Complex/Conjugate/conjugate1.fs new file mode 100644 index 00000000000..14a18db8c32 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Conjugate/conjugate1.fs @@ -0,0 +1,16 @@ +// +open System.Numerics + +let values = [ Complex(12.4, 6.3); + Complex(12.4, -6.3) ] + +for value in values do + printfn $"Original value: {value}" + printfn $"Conjugate: {Complex.Conjugate(value)}\n" +// The example displays the following output: +// Original value: (12.4, 6.3) +// Conjugate: (12.4, -6.3) +// +// Original value: (12.4, -6.3) +// Conjugate: (12.4, 6.3) +// diff --git a/snippets/fsharp/System.Numerics/Complex/Conjugate/fs.fsproj b/snippets/fsharp/System.Numerics/Complex/Conjugate/fs.fsproj new file mode 100644 index 00000000000..55a25506ca0 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Conjugate/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/Complex/Divide/divide1.fs b/snippets/fsharp/System.Numerics/Complex/Divide/divide1.fs new file mode 100644 index 00000000000..e5759a573d3 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Divide/divide1.fs @@ -0,0 +1,18 @@ +module divide1 + +// +open System.Numerics + +let c1 = Complex(1.2, 2.3); +let values = + [ Complex(1.2, 2.3) + Complex(0.5, 0.75) + Complex(3.0, -5.0) ] + +for c2 in values do + printfn $"{c1} / {c2} = {Complex.Divide(c1, c2):N2}" +// The example displays the following output: +// (1.2, 2.3) / (1.2, 2.3) = (1.00, 0.00) +// (1.2, 2.3) / (0.5, 0.75) = (2.86, 0.31) +// (1.2, 2.3) / (3, -5) = (-0.23, 0.38) +// \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/Complex/Divide/divide2.fs b/snippets/fsharp/System.Numerics/Complex/Divide/divide2.fs new file mode 100644 index 00000000000..304da70df05 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Divide/divide2.fs @@ -0,0 +1,9 @@ +module divide2 + +open System.Numerics + +// +let c1 = Complex(2.3, 3.7) +let c2 = Complex(1.4, 2.3) +let c3 = c1 / c2 +// diff --git a/snippets/fsharp/System.Numerics/Complex/Divide/fs.fsproj b/snippets/fsharp/System.Numerics/Complex/Divide/fs.fsproj new file mode 100644 index 00000000000..5ad2906dfd1 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Divide/fs.fsproj @@ -0,0 +1,11 @@ + + + Exe + net8.0 + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/Complex/Equals/eqoperator1.fs b/snippets/fsharp/System.Numerics/Complex/Equals/eqoperator1.fs new file mode 100644 index 00000000000..873903f1af7 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Equals/eqoperator1.fs @@ -0,0 +1,10 @@ +module eqoperator1 + +open System.Numerics + +// +let c1 = Complex(12.6, 4.3); +let c2 = Complex(11.1, 8.9); +if c1 = c2 then +// + () diff --git a/snippets/fsharp/System.Numerics/Complex/Equals/equals1.fs b/snippets/fsharp/System.Numerics/Complex/Equals/equals1.fs new file mode 100644 index 00000000000..a92b918f36e --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Equals/equals1.fs @@ -0,0 +1,23 @@ +module equals1 + +open System.Numerics + +type Complex2 = + val Real: float + val Imaginary: float + + member this.Equals(value: Complex2) = + // + this.Real.Equals value && this.Imaginary.Equals value + // + + override this.Equals(value: obj) = + // + this.Real.Equals((value :?> Complex).Real) + && this.Imaginary.Equals((value :?> Complex).Imaginary) + // + + member this.opEquality(value: Complex2) = + // + this.Real = value.Real && this.Imaginary = value.Imaginary +// diff --git a/snippets/fsharp/System.Numerics/Complex/Equals/equals3.fs b/snippets/fsharp/System.Numerics/Complex/Equals/equals3.fs new file mode 100644 index 00000000000..f07a0b9e4a4 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Equals/equals3.fs @@ -0,0 +1,7 @@ +module equals3 + +// +let n1 = 16.33; +let c1 = System.Numerics.Complex(16.33, 0) +printfn $"{c1.Equals n1}" // Returns true. +// \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/Complex/Equals/equals4.fs b/snippets/fsharp/System.Numerics/Complex/Equals/equals4.fs new file mode 100644 index 00000000000..48ae783aa57 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Equals/equals4.fs @@ -0,0 +1,10 @@ +module equals4 +// +open System.Numerics + +let n1 = 1.430718e-12f +let c1 = Complex(1.430718e-12, 0); +printfn $"{c1} = {n1}: {c1.Equals n1}" +// The example displays the following output: +// (1.430718E-12, 0) = 1.430718E-12: False +// diff --git a/snippets/fsharp/System.Numerics/Complex/Equals/fs.fsproj b/snippets/fsharp/System.Numerics/Complex/Equals/fs.fsproj new file mode 100644 index 00000000000..20e93793e3d --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Equals/fs.fsproj @@ -0,0 +1,15 @@ + + + Exe + net8.0 + + + + + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/Complex/Equals/precision1.fs b/snippets/fsharp/System.Numerics/Complex/Equals/precision1.fs new file mode 100644 index 00000000000..0a41d5c17ec --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Equals/precision1.fs @@ -0,0 +1,31 @@ +module precision1 + +open System + +let testForEquality () = + // + let c1 = System.Numerics.Complex(3.33333, 0.142857) + let c2 = System.Numerics.Complex(10. / 3., 1. / 7.) + printfn $"{c1} = {c2}: {c1.Equals c2}" +// The example displays the following output: +// (3.33333, 0.142857) = (3.33333333333333, 0.142857142857143): False +// + +let testForApproximateEquality () = + // + let c1 = System.Numerics.Complex(3.33333, 0.142857) + let c2 = System.Numerics.Complex(10. / 3., 1. / 7.) + let difference = 0.0001 + + // Compare the values + let result = + (Math.Abs(c1.Real - c2.Real) <= c1.Real * difference) + && (Math.Abs(c1.Imaginary - c2.Imaginary) <= c1.Imaginary * difference) + + printfn $"{c1} = {c2}: {result}" +// The example displays the following output: +// (3.33333, 0.142857) = (3.33333333333333, 0.142857142857143): True +// + +testForEquality () +testForApproximateEquality () diff --git a/snippets/fsharp/System.Numerics/Complex/Equals/precision2.fs b/snippets/fsharp/System.Numerics/Complex/Equals/precision2.fs new file mode 100644 index 00000000000..995ff6b2eeb --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Equals/precision2.fs @@ -0,0 +1,15 @@ +module precision2 + +// +open System.Numerics + +let n1 = 1.430718e-12f +let c1 = Complex(1.430718e-12, 0); +let difference = 0.0001f; + +// Compare the values +let result = (abs (c1.Real - float n1) <= c1.Real * float difference) && c1.Imaginary = 0; +printfn $"{c1} = {n1}: {result}" +// The example displays the following output: +// (1.430718E-12, 0) = 1.430718E-12: True +// diff --git a/snippets/fsharp/System.Numerics/Complex/Exp/fs.fsproj b/snippets/fsharp/System.Numerics/Complex/Exp/fs.fsproj new file mode 100644 index 00000000000..7089d0d7333 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Exp/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/Complex/Exp/log1.fs b/snippets/fsharp/System.Numerics/Complex/Exp/log1.fs new file mode 100644 index 00000000000..9ce95630c04 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Exp/log1.fs @@ -0,0 +1,20 @@ +// +open System +open System.Numerics + +let values = + [ Complex(1.53, 9.26) + Complex(2.53, -8.12) + Complex(-2.81, 5.32) + Complex(-1.09, -3.43) + Complex(Double.MinValue / 2.0, Double.MinValue / 2.0) ] + +for value in values do + printfn $"Exp(Log({value}) = {Complex.Exp(Complex.Log(value))}" +// The example displays the following output: +// Exp(Log((1.53, 9.26)) = (1.53, 9.26) +// Exp(Log((2.53, -8.12)) = (2.53, -8.12) +// Exp(Log((-2.81, 5.32)) = (-2.81, 5.32) +// Exp(Log((-1.09, -3.43)) = (-1.09, -3.43) +// Exp(Log((-8.98846567431158E+307, -8.98846567431158E+307)) = (-8.98846567431161E+307, -8.98846567431161E+307) +// diff --git a/snippets/fsharp/System.Numerics/Complex/FromPolarCoordinates/fs.fsproj b/snippets/fsharp/System.Numerics/Complex/FromPolarCoordinates/fs.fsproj new file mode 100644 index 00000000000..c6531b793d6 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/FromPolarCoordinates/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/Complex/FromPolarCoordinates/phase1.fs b/snippets/fsharp/System.Numerics/Complex/FromPolarCoordinates/phase1.fs new file mode 100644 index 00000000000..fe175378114 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/FromPolarCoordinates/phase1.fs @@ -0,0 +1,17 @@ +// +open System +open System.Numerics + +let c1 = Complex.FromPolarCoordinates(10., 45. * Math.PI / 180.) +printfn $"{c1}:" +printfn $" Magnitude: {Complex.Abs(c1)}" +printfn $" Phase: {c1.Phase} radians" +printfn $" Phase {c1.Phase * 180. / Math.PI} degrees" +printfn $" Atan(b/a): {Math.Atan(c1.Imaginary / c1.Real)}" +// The example displays the following output: +// (7.07106781186548, 7.07106781186547): +// Magnitude: 10 +// Phase: 0.785398163397448 radians +// Phase 45 degrees +// Atan(b/a): 0.785398163397448 +// diff --git a/snippets/fsharp/System.Numerics/Complex/Imaginary/fs.fsproj b/snippets/fsharp/System.Numerics/Complex/Imaginary/fs.fsproj new file mode 100644 index 00000000000..2480e33c2b8 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Imaginary/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/Complex/Imaginary/real1.fs b/snippets/fsharp/System.Numerics/Complex/Imaginary/real1.fs new file mode 100644 index 00000000000..c210e436655 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Imaginary/real1.fs @@ -0,0 +1,12 @@ +// +open System.Numerics + +let values = [ Complex(12.5, -6.3); Complex(-17.8, 1.7); Complex(14.4, 8.9) ] + +for value in values do + printfn $"{value.Real} + {value.Imaginary}i" +// The example displays the following output: +// 12.5 + -6.3i +// -17.8 + 1.7i +// 14.4 + 8.9i +// diff --git a/snippets/fsharp/System.Numerics/Complex/ImaginaryOne/fs.fsproj b/snippets/fsharp/System.Numerics/Complex/ImaginaryOne/fs.fsproj new file mode 100644 index 00000000000..32b7194f27e --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/ImaginaryOne/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/Complex/ImaginaryOne/imaginaryone1.fs b/snippets/fsharp/System.Numerics/Complex/ImaginaryOne/imaginaryone1.fs new file mode 100644 index 00000000000..142dff9327e --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/ImaginaryOne/imaginaryone1.fs @@ -0,0 +1,13 @@ +// +open System.Numerics + +let value = Complex.ImaginaryOne +printfn $"{value}" + +// Instantiate a complex number with real part 0 and imaginary part 1. +let value1 = Complex(0., 1.) +printfn $"{value.Equals value1}" +// The example displays the following output: +// (0, 1) +// True +// diff --git a/snippets/fsharp/System.Numerics/Complex/Multiply/fs.fsproj b/snippets/fsharp/System.Numerics/Complex/Multiply/fs.fsproj new file mode 100644 index 00000000000..a903ec503ce --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Multiply/fs.fsproj @@ -0,0 +1,11 @@ + + + Exe + net8.0 + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/Complex/Multiply/multiply1.fs b/snippets/fsharp/System.Numerics/Complex/Multiply/multiply1.fs new file mode 100644 index 00000000000..da0d5e05179 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Multiply/multiply1.fs @@ -0,0 +1,14 @@ +module multiply1 +// +open System.Numerics + +let number1 = Complex(8.3, 17.5) +let numbers = [ Complex(1.4, 6.3); Complex(-2.7, 1.8); Complex(3.1, -2.1) ] + +for number2 in numbers do + printfn $"{number1} x {number2} = {Complex.Multiply(number1, number2)}" +// The example displays the following output: +// (8.3, 17.5) x (1.4, 6.3) = (-98.63, 76.79) +// (8.3, 17.5) x (-2.7, 1.8) = (-53.91, -32.31) +// (8.3, 17.5) x (3.1, -2.1) = (62.48, 36.82) +// diff --git a/snippets/fsharp/System.Numerics/Complex/Multiply/multiply2.fs b/snippets/fsharp/System.Numerics/Complex/Multiply/multiply2.fs new file mode 100644 index 00000000000..45c97d4d4d0 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Multiply/multiply2.fs @@ -0,0 +1,9 @@ +module multiply2 + +open System.Numerics + +// +let c1 = Complex.One +let c2 = Complex(1.4, 2.3) +let c3 = c1 * c2 +// diff --git a/snippets/fsharp/System.Numerics/Complex/Negate/fs.fsproj b/snippets/fsharp/System.Numerics/Complex/Negate/fs.fsproj new file mode 100644 index 00000000000..cd2ceed98a5 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Negate/fs.fsproj @@ -0,0 +1,11 @@ + + + Exe + net8.0 + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/Complex/Negate/negate1.fs b/snippets/fsharp/System.Numerics/Complex/Negate/negate1.fs new file mode 100644 index 00000000000..7481b0cd28e --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Negate/negate1.fs @@ -0,0 +1,15 @@ +module negate1 +// +open System.Numerics + +let values = + [ Complex.One; Complex(-7.1, 2.5); Complex(1.3, -4.2); Complex(-3.3, -1.8) ] + +for c1 in values do + printfn $"{c1} --> {Complex.Negate(c1)}" +// The example displays the following output: +// (1, 0) --> (-1, 0) +// (-7.1, 2.5) --> (7.1, -2.5) +// (1.3, -4.2) --> (-1.3, 4.2) +// (-3.3, -1.8) --> (3.3, 1.8) +// diff --git a/snippets/fsharp/System.Numerics/Complex/Negate/negate2.fs b/snippets/fsharp/System.Numerics/Complex/Negate/negate2.fs new file mode 100644 index 00000000000..74f93b3908b --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Negate/negate2.fs @@ -0,0 +1,8 @@ +module negate2 + +open System.Numerics + +// +let c1 = Complex(1.7, 3.9) +let c2 = -c1 +// diff --git a/snippets/fsharp/System.Numerics/Complex/One/fs.fsproj b/snippets/fsharp/System.Numerics/Complex/One/fs.fsproj new file mode 100644 index 00000000000..be17b05fc0a --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/One/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/Complex/One/one1.fs b/snippets/fsharp/System.Numerics/Complex/One/one1.fs new file mode 100644 index 00000000000..7163c58f6ff --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/One/one1.fs @@ -0,0 +1,13 @@ +// +open System.Numerics + +let value = Complex.One +printfn $"{value}" + +// Instantiate a complex number with real part 1 and imaginary part 0. +let value1 = Complex(1., 0.) +printfn $"{value.Equals value1}" +// The example displays the following output: +// (1, 0) +// True +// diff --git a/snippets/fsharp/System.Numerics/Complex/Pow/fs.fsproj b/snippets/fsharp/System.Numerics/Complex/Pow/fs.fsproj new file mode 100644 index 00000000000..070cf48b7c6 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Pow/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/Complex/Pow/pow1.fs b/snippets/fsharp/System.Numerics/Complex/Pow/pow1.fs new file mode 100644 index 00000000000..04de9b552e9 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Pow/pow1.fs @@ -0,0 +1,21 @@ +// +open System.Numerics + +let value = Complex(12.0, -6.0) + +for power in -1. .. 10. do + printfn $"{value} ^ {power, 2} = {Complex.Pow(value, power):N2}" +// The example displays the following output: +// (12, -6) ^ -1 = (0.07, 0.03) +// (12, -6) ^ 0 = (1.00, 0.00) +// (12, -6) ^ 1 = (12.00, -6.00) +// (12, -6) ^ 2 = (108.00, -144.00) +// (12, -6) ^ 3 = (432.00, -2,376.00) +// (12, -6) ^ 4 = (-9,072.00, -31,104.00) +// (12, -6) ^ 5 = (-295,488.00, -318,816.00) +// (12, -6) ^ 6 = (-5,458,752.00, -2,052,864.00) +// (12, -6) ^ 7 = (-77,822,208.00, 8,118,144.00) +// (12, -6) ^ 8 = (-885,157,632.00, 564,350,976.00) +// (12, -6) ^ 9 = (-7,235,785,728.00, 12,083,157,504.00) +// (12, -6) ^ 10 = (-14,330,483,712.00, 188,412,604,416.00) +// diff --git a/snippets/fsharp/System.Numerics/Complex/Reciprocal/fs.fsproj b/snippets/fsharp/System.Numerics/Complex/Reciprocal/fs.fsproj new file mode 100644 index 00000000000..7eba8708d1c --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Reciprocal/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/Complex/Reciprocal/reciprocal1.fs b/snippets/fsharp/System.Numerics/Complex/Reciprocal/reciprocal1.fs new file mode 100644 index 00000000000..6b693b4e66b --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Reciprocal/reciprocal1.fs @@ -0,0 +1,15 @@ +// +open System.Numerics + +let values = + [ Complex(1., 1.); Complex(-1., 1.); Complex(10., -1.); Complex(3., 5.) ] + +for value in values do + let r1 = Complex.Reciprocal value + printfn $"{value:N0} x {r1:N2} = {value * r1:N2}" +// The example displays the following output: +// (1, 1) x (0.50, -0.50) = (1.00, 0.00) +// (-1, 1) x (-0.50, -0.50) = (1.00, 0.00) +// (10, -1) x (0.10, 0.01) = (1.00, 0.00) +// (3, 5) x (0.09, -0.15) = (1.00, 0.00) +// diff --git a/snippets/fsharp/System.Numerics/Complex/ToString/fs.fsproj b/snippets/fsharp/System.Numerics/Complex/ToString/fs.fsproj new file mode 100644 index 00000000000..0b5dabee768 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/ToString/fs.fsproj @@ -0,0 +1,13 @@ + + + Exe + net8.0 + + + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/Complex/ToString/tostring1.fs b/snippets/fsharp/System.Numerics/Complex/ToString/tostring1.fs new file mode 100644 index 00000000000..bf8b522612d --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/ToString/tostring1.fs @@ -0,0 +1,19 @@ +module tostring1 + +// +open System.Numerics + +let c = + [ Complex(17.3, 14.1) + Complex(-18.9, 147.2) + Complex(13.472, -18.115) + Complex(-11.154, -17.002) ] + +for c1 in c do + printfn $"{c1.ToString()}" +// The example display the following output: +// (17.3, 14.1) +// (-18.9, 147.2) +// (13.472, -18.115) +// (-11.154, -17.002) +// diff --git a/snippets/fsharp/System.Numerics/Complex/ToString/tostring2.fs b/snippets/fsharp/System.Numerics/Complex/ToString/tostring2.fs new file mode 100644 index 00000000000..42e681c1e76 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/ToString/tostring2.fs @@ -0,0 +1,24 @@ +module tostring2 +// +open System.Globalization +open System.Numerics + +let c = + [ Complex(17.3, 14.1) + Complex(-18.9, 147.2) + Complex(13.472, -18.115) + Complex(-11.154, -17.002) ] + +let cultures = [ CultureInfo "en-US"; CultureInfo "fr-FR" ] + +for c1 in c do + for culture in cultures do + printf $"{c1.ToString culture} ({culture.Name})" + + printfn "" +// The example displays the following output: +// (17.3, 14.1) (en-US) (17,3, 14,1) (fr-FR) +// (-18.9, 147.2) (en-US) (-18,9, 147,2) (fr-FR) +// (13.472, -18.115) (en-US) (13,472, -18,115) (fr-FR) +// (-11.154, -17.002) (en-US) (-11,154, -17,002) (fr-FR) +// diff --git a/snippets/fsharp/System.Numerics/Complex/ToString/tostring3.fs b/snippets/fsharp/System.Numerics/Complex/ToString/tostring3.fs new file mode 100644 index 00000000000..59930ba0e91 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/ToString/tostring3.fs @@ -0,0 +1,34 @@ +module tostring3 +// +open System.Numerics + +let c = + [ Complex(17.3, 14.1) + Complex(-18.9, 147.2) + Complex(13.472, -18.115) + Complex(-11.154, -17.002) ] + +let formats = [ "F2"; "N2"; "G5" ] + +for c1 in c do + for format in formats do + printf $"{format}: {c1.ToString(format)} " + + printfn "" +// The example displays the following output: +// F2: (17.30, 14.10) +// N2: (17.30, 14.10) +// G5: (17.3, 14.1) +// +// F2: (-18.90, 147.20) +// N2: (-18.90, 147.20) +// G5: (-18.9, 147.2) +// +// F2: (13.47, -18.12) +// N2: (13.47, -18.12) +// G5: (13.472, -18.115) +// +// F2: (-11.15, -17.00) +// N2: (-11.15, -17.00) +// G5: (-11.154, -17.002) +// diff --git a/snippets/fsharp/System.Numerics/Complex/ToString/tostring4.fs b/snippets/fsharp/System.Numerics/Complex/ToString/tostring4.fs new file mode 100644 index 00000000000..be702581a1d --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/ToString/tostring4.fs @@ -0,0 +1,39 @@ +module tostring4 +// +open System.Globalization +open System.Numerics + +let c = + [ Complex(17.3, 14.1) + Complex(-18.9, 147.2) + Complex(13.472, -18.115) + Complex(-11.154, -17.002) ] + +let cultures = [ CultureInfo "en-US"; CultureInfo "fr-FR" ] +let formats = [ "F2"; "N2"; "G5" ] + +for c1 in c do + for format in formats do + for culture in cultures do + printf $"{format} format string: {c1.ToString(format, culture)} ({culture.Name}) " + + printfn "" + + printfn "" +// The example displays the following output: +// F2 format string: (17.30, 14.10) (en-US) (17,30, 14,10) (fr-FR) +// N2 format string: (17.30, 14.10) (en-US) (17,30, 14,10) (fr-FR) +// G5 format string: (17.3, 14.1) (en-US) (17,3, 14,1) (fr-FR) +// +// F2 format string: (-18.90, 147.20) (en-US) (-18,90, 147,20) (fr-FR) +// N2 format string: (-18.90, 147.20) (en-US) (-18,90, 147,20) (fr-FR) +// G5 format string: (-18.9, 147.2) (en-US) (-18,9, 147,2) (fr-FR) +// +// F2 format string: (13.47, -18.12) (en-US) (13,47, -18,12) (fr-FR) +// N2 format string: (13.47, -18.12) (en-US) (13,47, -18,12) (fr-FR) +// G5 format string: (13.472, -18.115) (en-US) (13,472, -18,115) (fr-FR) +// +// F2 format string: (-11.15, -17.00) (en-US) (-11,15, -17,00) (fr-FR) +// N2 format string: (-11.15, -17.00) (en-US) (-11,15, -17,00) (fr-FR) +// G5 format string: (-11.154, -17.002) (en-US) (-11,154, -17,002) (fr-FR) +// diff --git a/snippets/fsharp/System.Numerics/Complex/Zero/fs.fsproj b/snippets/fsharp/System.Numerics/Complex/Zero/fs.fsproj new file mode 100644 index 00000000000..61cb81bcddb --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Zero/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/Complex/Zero/zero1.fs b/snippets/fsharp/System.Numerics/Complex/Zero/zero1.fs new file mode 100644 index 00000000000..fcbcfd1fe37 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/Zero/zero1.fs @@ -0,0 +1,13 @@ +// +open System.Numerics + +let value = Complex.Zero +printfn $"{value}" + +// Instantiate a complex number with real part 0 and imaginary part 1. +let value1 = Complex(0, 0) +printfn $"{value.Equals value1}" +// The example displays the following output: +// (0, 0) +// True +// diff --git a/snippets/fsharp/System.Numerics/Complex/op_Explicit/explicit1.fs b/snippets/fsharp/System.Numerics/Complex/op_Explicit/explicit1.fs new file mode 100644 index 00000000000..55ea830b198 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/op_Explicit/explicit1.fs @@ -0,0 +1,38 @@ +open System +open System.Numerics + +let fromDecimal () = + // + let numbers = [ Decimal.MinValue; -18.35m; 0m; 1893.019m; Decimal.MaxValue ] + + for number in numbers do + let c1 = Complex(float number, 0.) + printfn $"{number, 30} --> {c1}" + +// The example displays the following output: +// -79228162514264337593543950335 --> (-7.92281625142643E+28, 0) +// -18.35 --> (-18.35, 0) +// 0 --> (0, 0) +// 1893.019 --> (1893.019, 0) +// 79228162514264337593543950335 --> (7.92281625142643E+28, 0) +// + +let fromBigInteger () = + // + let numbers = + [ (bigint Double.MaxValue) * 2I + BigInteger.Parse "901345277852317852466891423" + BigInteger.One ] + + for number in numbers do + let c1 = Complex(float number, 0.) + printfn $"{number, 30} --> {c1}" +// The example displays the following output: +// (Infinity, 0) +// (9.01345277852318E+26, 0) +// (1, 0) +// + + +fromDecimal () +fromBigInteger () diff --git a/snippets/fsharp/System.Numerics/Complex/op_Explicit/fs.fsproj b/snippets/fsharp/System.Numerics/Complex/op_Explicit/fs.fsproj new file mode 100644 index 00000000000..482c9ab21a3 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/op_Explicit/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/Complex/op_Implicit/fs.fsproj b/snippets/fsharp/System.Numerics/Complex/op_Implicit/fs.fsproj new file mode 100644 index 00000000000..1c059d7abc6 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/op_Implicit/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/Complex/op_Implicit/implicit1.fs b/snippets/fsharp/System.Numerics/Complex/op_Implicit/implicit1.fs new file mode 100644 index 00000000000..974d85fd23f --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/op_Implicit/implicit1.fs @@ -0,0 +1,110 @@ +let complexFromByte () = + + // + let byteValue = 122 + let c1: System.Numerics.Complex = byteValue + printfn $"{c1}" + // The example displays the following output: + // (122, 0) + // + +let complexFromDouble () = + + // + let doubleValue = 1.032e-16 + let c1: System.Numerics.Complex = doubleValue + printfn $"{c1}" + // The example displays the following output: + // (1.032E-16, 0) + // + +let complexFromInt16 () = + + // + let shortValue = 16024 + let c1: System.Numerics.Complex = shortValue + printfn $"{c1}" + // The example displays the following output: + // (16024, 0) + // + +let complexFromInt32 () = + + // + let intValue = 1034217 + let c1: System.Numerics.Complex = intValue + printfn $"{c1}" + // The example displays the following output: + // (1034217, 0) + // + +let complexFromInt64 () = + + // + let longValue = 951034217 + let c1: System.Numerics.Complex = longValue + printfn $"{c1}" + // The example displays the following output: + // (951034217, 0) + // + +let complexFromSByte () = + + // + let sbyteValue = -12 + let c1: System.Numerics.Complex = sbyteValue + printfn $"{c1}" + // The example displays the following output: + // (-12, 0) + // + +let complexFromSingle () = + + // + let singleValue = 1.032e-08f + let c1: System.Numerics.Complex = singleValue + printfn $"{c1}" + // The example displays the following output: + // (1.03199999657022E-08, 0) + // + +let complexFromUInt16 () = + + // + let shortValue = 421 + let c1: System.Numerics.Complex = shortValue + printfn $"{c1}" + // The example displays the following output: + // (421, 0) + // + +let complexFromUInt32 () = + + // + let value = 197461 + let c1: System.Numerics.Complex = value + printfn $"{c1}" + // The example displays the following output: + // (197461, 0) + // + +let complexFromUInt64 () = + + // + let longValue = 951034217 + let c1: System.Numerics.Complex = longValue + printfn $"{c1}" + // The example displays the following output: + // (951034217, 0) + // + +complexFromByte () +complexFromDouble () +complexFromInt16 () +complexFromInt32 () +complexFromInt64 () +complexFromSByte () +complexFromSingle () +complexFromUInt16 () +complexFromUInt32 () +complexFromUInt64 () diff --git a/snippets/fsharp/System.Numerics/Complex/op_Inequality/fs.fsproj b/snippets/fsharp/System.Numerics/Complex/op_Inequality/fs.fsproj new file mode 100644 index 00000000000..e26ac7c2df7 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/op_Inequality/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/Complex/op_Inequality/inequality1.fs b/snippets/fsharp/System.Numerics/Complex/op_Inequality/inequality1.fs new file mode 100644 index 00000000000..cfe3f42d3eb --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/op_Inequality/inequality1.fs @@ -0,0 +1,9 @@ +open System.Numerics + +// +let c1 = Complex(12.6, 4.3) +let c2 = Complex(11.1, 8.9) + +if c1 <> c2 then + // + () diff --git a/snippets/fsharp/System.Numerics/Complex/op_Subtraction/fs.fsproj b/snippets/fsharp/System.Numerics/Complex/op_Subtraction/fs.fsproj new file mode 100644 index 00000000000..69e94a24f61 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/op_Subtraction/fs.fsproj @@ -0,0 +1,11 @@ + + + Exe + net8.0 + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Numerics/Complex/op_Subtraction/subtract1.fs b/snippets/fsharp/System.Numerics/Complex/op_Subtraction/subtract1.fs new file mode 100644 index 00000000000..cc7b44f57f0 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/op_Subtraction/subtract1.fs @@ -0,0 +1,20 @@ +module subtract1 +// +open System.Numerics + +let c1 = Complex(4.93, 6.87) + +let values = + [ Complex(12.5, 9.6) + Complex(4.3, -8.1) + Complex(-1.9, 7.4) + Complex(-5.3, -6.6) ] + +for c2 in values do + printfn $"{c1} - {c2} = {Complex.Subtract(c1, c2)}" +// The example displays the following output: +// (4.93, 6.87) - (12.5, 9.6) = (-7.57, -2.73) +// (4.93, 6.87) - (4.3, -8.1) = (0.63, 14.97) +// (4.93, 6.87) - (-1.9, 7.4) = (6.83, -0.53) +// (4.93, 6.87) - (-5.3, -6.6) = (10.23, 13.47) +// diff --git a/snippets/fsharp/System.Numerics/Complex/op_Subtraction/subtract2.fs b/snippets/fsharp/System.Numerics/Complex/op_Subtraction/subtract2.fs new file mode 100644 index 00000000000..11f415c9cd3 --- /dev/null +++ b/snippets/fsharp/System.Numerics/Complex/op_Subtraction/subtract2.fs @@ -0,0 +1,9 @@ +module subtract2 +// +let c1 = System.Numerics.Complex(6.7, -1.3) +let c2 = System.Numerics.Complex(1.4, 3.8) +let result = c1 - c2 +printfn $"{c1}; - {c2}; = {result}" +// The example displays the following output: +// (6.7, -1.3); - (1.4, 3.8); = (5.3, -5.1) +// diff --git a/xml/System.Numerics/Complex.xml b/xml/System.Numerics/Complex.xml index babc01dd4c9..cb63b9992bc 100644 --- a/xml/System.Numerics/Complex.xml +++ b/xml/System.Numerics/Complex.xml @@ -232,6 +232,7 @@ The following example instantiates two complex numbers, and then uses them in addition, subtraction, multiplication, and division operations. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/.ctor/ctor1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/.ctor/ctor1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.ctor/vb/ctor1.vb" id="Snippet1"::: ]]> @@ -298,6 +299,7 @@ The following example calculates the absolute value of a complex number and demonstrates that it is equivalent to the value of the property. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/Abs/abs1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/Abs/abs1.fs" id="Snippet1"::: ]]> @@ -360,6 +362,7 @@ The following example illustrates the method. It shows that passing the value returned by the method to the method returns the original value. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/Acos/acos1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/Acos/acos1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.acos/vb/acos1.vb" id="Snippet1"::: ]]> @@ -388,6 +391,7 @@ The following example illustrates addition with complex numbers. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/Add/add1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/Add/add1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.add/vb/add1.vb" id="Snippet1"::: ]]> @@ -605,6 +609,7 @@ The addition of a complex number (a + bi) and a real number (which can be regard The following example illustrates the method. It shows that passing the value returned by the method to the method returns the original value. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/Asin/asin1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/Asin/asin1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.asin/vb/asin1.vb" id="Snippet1"::: ]]> @@ -669,6 +674,7 @@ The addition of a complex number (a + bi) and a real number (which can be regard The following example illustrates the method. It shows that passing the value returned by the method to the method returns the original value. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/Atan/atan1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/Atan/atan1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.atan/vb/atan1.vb" id="Snippet1"::: ]]> @@ -729,6 +735,7 @@ The addition of a complex number (a + bi) and a real number (which can be regard The following example displays the conjugate of two complex numbers. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/Conjugate/conjugate1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/Conjugate/conjugate1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.conjugate/vb/conjugate1.vb" id="Snippet1"::: ]]> @@ -791,6 +798,7 @@ The addition of a complex number (a + bi) and a real number (which can be regard The following example illustrates the method. It shows that passing the value returned by the method to the method returns the original value. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/Acos/acos1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/Acos/acos1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.acos/vb/acos1.vb" id="Snippet1"::: ]]> @@ -1044,6 +1052,7 @@ The addition of a complex number (a + bi) and a real number (which can be regard The following example divides a complex number by each element in an array of complex numbers. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/Divide/divide1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/Divide/divide1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.divide/vb/divide1.vb" id="Snippet1"::: ]]> @@ -1274,6 +1283,7 @@ The addition of a complex number (a + bi) and a real number (which can be regard Two complex numbers are equal if their real parts are equal and their imaginary parts are equal. The method is equivalent to the following expression: :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/Equals/equals1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/Equals/equals1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.equals/vb/equals1.vb" id="Snippet1"::: ]]> @@ -1282,11 +1292,13 @@ The addition of a complex number (a + bi) and a real number (which can be regard Use the method with caution, because two values that are apparently equivalent can be considered unequal due to the differing precision of their real and imaginary components. The following example reports that (3.33333, 0.142857) and (10/3, 1/7) are not equal. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/Equals/precision1.cs" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/Equals/precision1.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.equals/vb/precision1.vb" id="Snippet4"::: One recommended technique is to define an acceptable margin of difference between the two values (such as .01% of one of the values' real and imaginary components) instead of comparing the values for equality. If the absolute value of the difference between the two values is less than or equal to that margin, the difference is likely to be due to a difference in precision, and, therefore, the values are likely to be equal. The following example uses this technique to compare the two complex values that the previous code example found to be unequal. It finds the two complex numbers to be equal. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/Equals/precision1.cs" id="Snippet5"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/Equals/precision1.fs" id="Snippet5"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.equals/vb/precision1.vb" id="Snippet5"::: @@ -1354,11 +1366,13 @@ The addition of a complex number (a + bi) and a real number (which can be regard Two complex numbers are equal if their real parts are equal and their imaginary parts are equal. The method is equivalent to the following expression: :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/Equals/equals1.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/Equals/equals1.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.equals/vb/equals1.vb" id="Snippet2"::: If the `obj` parameter is not a object, but it is a data type for which an implicit conversion is defined, the method converts `obj` to a object whose real part is equal to the value of `obj` and whose imaginary part is equal to zero before it performs the comparison. The following example illustrates this by finding that a complex number and a double-precision floating-point value are equal. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/Equals/equals3.cs" id="Snippet6"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/Equals/equals3.fs" id="Snippet6"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.equals/vb/equals3.vb" id="Snippet6"::: ]]> @@ -1367,11 +1381,13 @@ The addition of a complex number (a + bi) and a real number (which can be regard Use the method with caution, because two values that are apparently equivalent can be considered unequal due to the differing precision of their real and imaginary components. The problem can be accentuated if must be converted to a before performing the comparison. The following example compares a complex number whose real component appears to be equal to a value with that value. As the output shows, the comparison for equality returns . :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/Equals/equals4.cs" id="Snippet8"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/Equals/equals4.fs" id="Snippet8"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.equals/vb/equals4.vb" id="Snippet8"::: One recommended technique is to define an acceptable margin of difference between the two values (such as .01% of one of the values' real and imaginary components) instead of comparing the values for equality. If the absolute value of the difference between the two values is less than or equal to that margin, the difference is likely to be due to a difference in precision and, therefore, the values are likely to be equal. The following example uses this technique to compare the two values that the previous code example found to be unequal. It now finds them to be equal. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/Equals/precision2.cs" id="Snippet7"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/Equals/precision2.fs" id="Snippet7"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.equals/vb/precision2.vb" id="Snippet7"::: @@ -1430,6 +1446,7 @@ The addition of a complex number (a + bi) and a real number (which can be regard The following example illustrates the method. It shows that, with some allowance for the lack of precision of the data type, passing the value returned by the method to the method returns the original value. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/Exp/log1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/Exp/log1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.log/vb/log1.vb" id="Snippet1"::: ]]> @@ -1495,6 +1512,7 @@ The addition of a complex number (a + bi) and a real number (which can be regard The following example uses the method to instantiate a complex number based on its polar coordinates and then displays the value of its and properties. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/FromPolarCoordinates/phase1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/FromPolarCoordinates/phase1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.phase/vb/phase1.vb" id="Snippet1"::: ]]> @@ -1597,6 +1615,7 @@ The addition of a complex number (a + bi) and a real number (which can be regard The following example instantiates an array of objects and displays the real and imaginary components of each in the form a + bi. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/Imaginary/real1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/Imaginary/real1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.real/vb/real1.vb" id="Snippet1"::: ]]> @@ -1646,6 +1665,7 @@ The addition of a complex number (a + bi) and a real number (which can be regard The following example instantiates a value by using the property. It then compares this value to another value that is instantiated by calling the constructor with a real part equal to zero and an imaginary part equal to one. As the output from the example shows, the two values are equal. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/ImaginaryOne/imaginaryone1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/ImaginaryOne/imaginaryone1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.imaginaryone/vb/imaginaryone1.vb" id="Snippet1"::: ]]> @@ -2398,6 +2418,7 @@ This function returns `true` for a complex number `a + bi` where `b` is zero. The following example illustrates the method. It shows that, with some allowance for the lack of precision of the data type, passing the value returned by the method to the method returns the original value. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/Exp/log1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/Exp/log1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.log/vb/log1.vb" id="Snippet1"::: ]]> @@ -2564,6 +2585,7 @@ This function returns `true` for a complex number `a + bi` where `b` is zero. The following example calculates the absolute value of a complex number and demonstrates that it is equivalent to the value of the property. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/Abs/abs1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/Abs/abs1.fs" id="Snippet1"::: ]]> @@ -2687,6 +2709,7 @@ The method is implemented for languag The following example multiples a complex number by each element in an array of complex numbers. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/Multiply/multiply1.cs" interactive="try-dotnet" id="Snippet1"::: +:::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/Multiply/multiply1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.multiply/vb/multiply1.vb" id="Snippet1"::: ]]> @@ -2944,6 +2967,7 @@ ac + bci The following example obtains the additive inverse of each element in an array of complex numbers. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/Negate/negate1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/Negate/negate1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.negate/vb/negate1.vb" id="Snippet1"::: ]]> @@ -2993,6 +3017,7 @@ ac + bci The following example instantiates a value by using the property. It then compares this value to another value that is instantiated by calling the constructor with a real part equal to one and an imaginary part equal to zero. As the output from the example shows, the two values are equal. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/One/one1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/One/one1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.one/vb/one1.vb" id="Snippet1"::: ]]> @@ -3012,6 +3037,7 @@ ac + bci The operator allows performing addition operations that involve complex numbers. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/Add/add3.cs" id="Snippet3"::: +:::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/Add/add3.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.add/vb/add3.vb" id="Snippet3"::: If the addition results in an overflow in either the real or imaginary component, the value of that component is either or . @@ -3025,6 +3051,7 @@ The operators that receive one dou The following example illustrates addition with complex numbers: :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/Add/add2.cs" interactive="try-dotnet" id="Snippet2"::: +:::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/Add/add2.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.add/vb/add2.vb" id="Snippet2"::: ]]> @@ -3245,6 +3272,7 @@ Languages that do not support custom operators can call the operator allows performing division operations that involve complex numbers. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/Divide/divide2.cs" id="Snippet2"::: +:::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/Divide/divide2.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.divide/vb/divide2.vb" id="Snippet2"::: If the division results in an overflow in either the real or imaginary component, the value of that component is either or . @@ -3477,6 +3505,7 @@ Languages that do not support custom operators and operator overloading can call The method defines the operation of the equality operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/Equals/eqoperator1.cs" id="Snippet9"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/Equals/eqoperator1.fs" id="Snippet9"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.equals/vb/eqoperator1.vb" id="Snippet9"::: Languages that do not support custom operators can call the method instead. @@ -3484,6 +3513,7 @@ Languages that do not support custom operators and operator overloading can call Two complex numbers are equal if their real parts are equal and their imaginary parts are equal. The method is equivalent to the following expression: :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/Equals/equals1.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/Equals/equals1.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.equals/vb/equals1.vb" id="Snippet3"::: Note that, because of differences in precision, two complex numbers that are apparently equivalent can be considered unequal. For more information and a possible workaround, see the method. @@ -3557,6 +3587,7 @@ Languages that do not support custom operators and operator overloading can call The following example illustrates the explicit conversion of values to values. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/op_Explicit/explicit1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/op_Explicit/explicit1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.explicit/vb/explicit1.vb" id="Snippet1"::: ]]> @@ -3653,6 +3684,7 @@ Languages that do not support custom operators and operator overloading can call The following example illustrates the explicit conversion of values to values. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/op_Explicit/explicit1.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/op_Explicit/explicit1.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.explicit/vb/explicit1.vb" id="Snippet2"::: ]]> @@ -3758,6 +3790,7 @@ Languages that do not support custom operators and operator overloading can call This overload lets the compiler handle conversions from a value to a complex number, as the following example shows. Note that the result of the conversion is a complex number whose real part is equal to the value and whose imaginary part is equal to zero. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/op_Implicit/implicit1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/op_Implicit/implicit1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.implicit/vb/implicit1.vb" id="Snippet1"::: ]]> @@ -3847,6 +3880,7 @@ Languages that do not support custom operators and operator overloading can call This overload lets the compiler handle conversions from a value to a complex number, as the following example shows. Note that the result of the conversion is a complex number whose real part is equal to the value and whose imaginary part is equal to zero. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/op_Implicit/implicit1.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/op_Implicit/implicit1.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.implicit/vb/implicit1.vb" id="Snippet2"::: ]]> @@ -3936,6 +3970,7 @@ Languages that do not support custom operators and operator overloading can call This overload lets the compiler handle conversions from a signed 16-bit integer to a complex number, as the following example shows. Note that the result of the conversion is a complex number whose real part is equal to the signed 16-bit integer and whose imaginary part is equal to zero. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/op_Implicit/implicit1.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/op_Implicit/implicit1.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.implicit/vb/implicit1.vb" id="Snippet3"::: ]]> @@ -3991,6 +4026,7 @@ Languages that do not support custom operators and operator overloading can call This overload lets the compiler handle conversions from a signed 32-bit integer to a complex number, as the following example shows. Note that the result of the conversion is a complex number whose real part is equal to the signed 32-bit integer and whose imaginary part is equal to zero. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/op_Implicit/implicit1.cs" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/op_Implicit/implicit1.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.implicit/vb/implicit1.vb" id="Snippet4"::: ]]> @@ -4046,6 +4082,7 @@ Languages that do not support custom operators and operator overloading can call This overload lets the compiler handle conversions from a signed 64-bit integer to a complex number, as the following example shows. Note that the result of the conversion is a complex number whose real part is equal to the signed 64-bit integer and whose imaginary part is equal to zero. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/op_Implicit/implicit1.cs" id="Snippet5"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/op_Implicit/implicit1.fs" id="Snippet5"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.implicit/vb/implicit1.vb" id="Snippet5"::: ]]> @@ -4143,6 +4180,7 @@ This API is not CLS-compliant. This overload lets the compiler handle conversions from a signed byte to a complex number, as the following example shows. Note that the result of the conversion is a complex number whose real part is equal to the signed byte and whose imaginary part is equal to zero. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/op_Implicit/implicit1.cs" id="Snippet6"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/op_Implicit/implicit1.fs" id="Snippet6"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.implicit/vb/implicit1.vb" id="Snippet6"::: ]]> @@ -4198,6 +4236,7 @@ This API is not CLS-compliant. This overload lets the compiler handle conversions from a value to a complex number, as the following example shows. Note that the result of the conversion is a complex number whose real part is equal to the value and whose imaginary part is equal to zero. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/op_Implicit/implicit1.cs" id="Snippet7"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/op_Implicit/implicit1.fs" id="Snippet7"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.implicit/vb/implicit1.vb" id="Snippet7"::: ]]> @@ -4261,6 +4300,7 @@ This API is not CLS-compliant. This overload lets the compiler handle conversions from an unsigned 16-bit integer to a complex number, as the following example shows. Note that the result of the conversion is a complex number whose real part is equal to the unsigned 16-bit integer and whose imaginary part is equal to zero. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/op_Implicit/implicit1.cs" id="Snippet8"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/op_Implicit/implicit1.fs" id="Snippet8"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.implicit/vb/implicit1.vb" id="Snippet8"::: ]]> @@ -4324,6 +4364,7 @@ This API is not CLS-compliant. This overload lets the compiler handle conversions from an unsigned 32-bit integer to a complex number, as the following example shows. Note that the result of the conversion is a complex number whose real part is equal to the unsigned 32-bit integer and whose imaginary part is equal to zero. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/op_Implicit/implicit1.cs" id="Snippet9"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/op_Implicit/implicit1.fs" id="Snippet9"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.implicit/vb/implicit1.vb" id="Snippet9"::: ]]> @@ -4387,6 +4428,7 @@ This API is not CLS-compliant. This overload lets the compiler handle conversions from an unsigned 64-bit integer to a complex number, as the following example shows. Note that the result of the conversion is a complex number whose real part is equal to the unsigned 64-bit integer and whose imaginary part is equal to zero. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/op_Implicit/implicit1.cs" id="Snippet10"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/op_Implicit/implicit1.fs" id="Snippet10"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.implicit/vb/implicit1.vb" id="Snippet10"::: ]]> @@ -4524,6 +4566,7 @@ This API is not CLS-compliant. The method defines the operation of the inequality operator for complex numbers. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/op_Inequality/inequality1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/op_Inequality/inequality1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.inequality/vb/inequality1.vb" id="Snippet1"::: Languages that do not support custom operators can test for inequality by calling the method and reversing its value. @@ -4546,6 +4589,7 @@ This API is not CLS-compliant. The operator allows performing multiplication operations that involve complex numbers. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/Multiply/multiply2.cs" id="Snippet2"::: +:::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/Multiply/multiply2.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.multiply/vb/multiply2.vb" id="Snippet2"::: If the multiplication results in an overflow in either the real or imaginary component, the value of that component is either or . @@ -4736,6 +4780,7 @@ Languages that do not support custom operators can call the operator allows performing subtraction operations that involve complex numbers. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/op_Subtraction/subtract2.cs" id="Snippet2"::: +:::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/op_Subtraction/subtract2.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.subtract/vb/subtract2.vb" id="Snippet2"::: If the subtraction results in an overflow in either the real or imaginary component, the value of that component is either or . @@ -4965,6 +5010,7 @@ Languages that do not support custom operators can call the method defines the operation of the unary negation (additive inverse) operator for complex numbers. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/Negate/negate2.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/Negate/negate2.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.negate/vb/negate2.vb" id="Snippet2"::: The resulting complex number produces a value of when it is added to the original complex number. Languages that do not support custom operators can call the method instead. @@ -5265,6 +5311,7 @@ Languages that do not support custom operators can call the method to instantiate a complex number based on its polar coordinates, and then displays the value of its and properties. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/FromPolarCoordinates/phase1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/FromPolarCoordinates/phase1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.phase/vb/phase1.vb" id="Snippet1"::: ]]> @@ -5338,6 +5385,7 @@ Languages that do not support custom operators can call the @@ -5443,6 +5491,7 @@ Languages that do not support custom operators can call the objects and displays the real and imaginary components of each in the form a + bi. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/Imaginary/real1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/Imaginary/real1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.real/vb/real1.vb" id="Snippet1"::: ]]> @@ -5504,6 +5553,7 @@ Languages that do not support custom operators can call the method to calculate the reciprocal values of several complex numbers. It also demonstrates that the result of multiplying a complex number by its reciprocal is . :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/Reciprocal/reciprocal1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/Reciprocal/reciprocal1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.reciprocal/vb/reciprocal1.vb" id="Snippet1"::: ]]> @@ -5566,6 +5616,7 @@ Languages that do not support custom operators can call the method. It shows that passing the value returned by the method to the method returns the original value. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/Asin/asin1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/Asin/asin1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.asin/vb/asin1.vb" id="Snippet1"::: ]]> @@ -5704,6 +5755,7 @@ The methods that receive one double a The following example subtracts each complex number in an array from a complex number: :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/op_Subtraction/subtract1.cs" interactive="try-dotnet" id="Snippet1"::: +:::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/op_Subtraction/subtract1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.subtract/vb/subtract1.vb" id="Snippet1"::: ]]> @@ -6643,6 +6695,7 @@ Languages that support custom operators can use the method. It shows that passing the value returned by the method to the method returns the original value. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/Atan/atan1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/Atan/atan1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.atan/vb/atan1.vb" id="Snippet1"::: ]]> @@ -6771,6 +6824,7 @@ Languages that support custom operators can use the @@ -6853,6 +6907,7 @@ Languages that support custom operators can use the @@ -6937,6 +6992,7 @@ Languages that support custom operators can use the @@ -7034,6 +7090,7 @@ Languages that support custom operators can use the objects that represent the English - United States ("en-US") and French - France ("fr-FR") cultures. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/ToString/tostring4.cs" interactive="try-dotnet" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/ToString/tostring4.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.tostring/vb/tostring4.vb" id="Snippet4"::: ]]> @@ -7415,6 +7472,7 @@ An implementation of this interface should produce the same string of characters The following example instantiates a value by using the property. It then compares this value to another value that is instantiated by calling the constructor with a real part equal to zero and an imaginary part equal to zero. As the output from the example shows, the two values are equal. :::code language="csharp" source="~/snippets/csharp/System.Numerics/Complex/Zero/zero1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Numerics/Complex/Zero/zero1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.numerics.complex.zero/vb/zero1.vb" id="Snippet1"::: ]]> From 2e09bef42f6726cf69e028f11bb8837330ff9fe2 Mon Sep 17 00:00:00 2001 From: Albert Du <52804499+albert-du@users.noreply.github.com> Date: Mon, 24 Jun 2024 07:26:03 -0700 Subject: [PATCH 05/10] F# snippets for System.Diagnostics.Process (#10053) --- .../Overview/datareceivedevent.fs | 39 ++++ .../DataReceivedEventArgs/Overview/fs.fsproj | 13 ++ .../Overview/net_async.fs | 156 +++++++++++++++ .../Overview/nmake_async.fs | 178 ++++++++++++++++++ .../Overview/sort_async.fs | 97 ++++++++++ .../Process/BasePriority/fs.fsproj | 10 + .../Process/BasePriority/source.fs | 58 ++++++ .../Process/Close/fs.fsproj | 10 + .../Process/Close/process_refresh.fs | 42 +++++ .../Process/EnableRaisingEvents/fs.fsproj | 10 + .../EnableRaisingEvents/processexitedevent.fs | 49 +++++ .../Process/GetCurrentProcess/fs.fsproj | 10 + .../GetCurrentProcess/processstaticget.fs | 34 ++++ .../System.Diagnostics/Process/Id/fs.fsproj | 10 + .../System.Diagnostics/Process/Id/program.fs | 38 ++++ .../Process/MachineName/fs.fsproj | 10 + .../process_getprocessesbyname2_2.fs | 31 +++ .../Process/MainWindowTitle/fs.fsproj | 10 + .../process_mainwindowtitle.fs | 20 ++ .../Process/OnExited/fs.fsproj | 10 + .../Process/OnExited/program.fs | 23 +++ .../Process/Overview/fs.fsproj | 11 ++ .../Process/Overview/processstart.fs | 19 ++ .../Process/Overview/processstartstatic.fs | 41 ++++ .../Process/StandardError/fs.fsproj | 11 ++ .../Process/StandardError/source.fs | 15 ++ .../Process/StandardError/stderror-sync.fs | 18 ++ .../Process/StandardInput/fs.fsproj | 10 + .../StandardInput/process_standardinput.fs | 58 ++++++ .../Process/StandardOutput/fs.fsproj | 13 ++ .../StandardOutput/process_standardoutput.fs | 21 +++ .../Process/StandardOutput/stdoutput-async.fs | 28 +++ .../Process/StandardOutput/stdoutput-sync.fs | 22 +++ .../Process/StandardOutput/write500lines.fs | 13 ++ .../Process/Start/fs.fsproj | 10 + .../Process/Start/program.fs | 54 ++++++ .../Process/SynchronizingObject/fs.fsproj | 10 + .../Process/SynchronizingObject/remarks.fs | 12 ++ .../Process/WorkingSet/fs.fsproj | 10 + .../Process/WorkingSet/process_sample.fs | 46 +++++ xml/System.Diagnostics/Process.xml | 60 ++++++ 41 files changed, 1340 insertions(+) create mode 100644 snippets/fsharp/System.Diagnostics/DataReceivedEventArgs/Overview/datareceivedevent.fs create mode 100644 snippets/fsharp/System.Diagnostics/DataReceivedEventArgs/Overview/fs.fsproj create mode 100644 snippets/fsharp/System.Diagnostics/DataReceivedEventArgs/Overview/net_async.fs create mode 100644 snippets/fsharp/System.Diagnostics/DataReceivedEventArgs/Overview/nmake_async.fs create mode 100644 snippets/fsharp/System.Diagnostics/DataReceivedEventArgs/Overview/sort_async.fs create mode 100644 snippets/fsharp/System.Diagnostics/Process/BasePriority/fs.fsproj create mode 100644 snippets/fsharp/System.Diagnostics/Process/BasePriority/source.fs create mode 100644 snippets/fsharp/System.Diagnostics/Process/Close/fs.fsproj create mode 100644 snippets/fsharp/System.Diagnostics/Process/Close/process_refresh.fs create mode 100644 snippets/fsharp/System.Diagnostics/Process/EnableRaisingEvents/fs.fsproj create mode 100644 snippets/fsharp/System.Diagnostics/Process/EnableRaisingEvents/processexitedevent.fs create mode 100644 snippets/fsharp/System.Diagnostics/Process/GetCurrentProcess/fs.fsproj create mode 100644 snippets/fsharp/System.Diagnostics/Process/GetCurrentProcess/processstaticget.fs create mode 100644 snippets/fsharp/System.Diagnostics/Process/Id/fs.fsproj create mode 100644 snippets/fsharp/System.Diagnostics/Process/Id/program.fs create mode 100644 snippets/fsharp/System.Diagnostics/Process/MachineName/fs.fsproj create mode 100644 snippets/fsharp/System.Diagnostics/Process/MachineName/process_getprocessesbyname2_2.fs create mode 100644 snippets/fsharp/System.Diagnostics/Process/MainWindowTitle/fs.fsproj create mode 100644 snippets/fsharp/System.Diagnostics/Process/MainWindowTitle/process_mainwindowtitle.fs create mode 100644 snippets/fsharp/System.Diagnostics/Process/OnExited/fs.fsproj create mode 100644 snippets/fsharp/System.Diagnostics/Process/OnExited/program.fs create mode 100644 snippets/fsharp/System.Diagnostics/Process/Overview/fs.fsproj create mode 100644 snippets/fsharp/System.Diagnostics/Process/Overview/processstart.fs create mode 100644 snippets/fsharp/System.Diagnostics/Process/Overview/processstartstatic.fs create mode 100644 snippets/fsharp/System.Diagnostics/Process/StandardError/fs.fsproj create mode 100644 snippets/fsharp/System.Diagnostics/Process/StandardError/source.fs create mode 100644 snippets/fsharp/System.Diagnostics/Process/StandardError/stderror-sync.fs create mode 100644 snippets/fsharp/System.Diagnostics/Process/StandardInput/fs.fsproj create mode 100644 snippets/fsharp/System.Diagnostics/Process/StandardInput/process_standardinput.fs create mode 100644 snippets/fsharp/System.Diagnostics/Process/StandardOutput/fs.fsproj create mode 100644 snippets/fsharp/System.Diagnostics/Process/StandardOutput/process_standardoutput.fs create mode 100644 snippets/fsharp/System.Diagnostics/Process/StandardOutput/stdoutput-async.fs create mode 100644 snippets/fsharp/System.Diagnostics/Process/StandardOutput/stdoutput-sync.fs create mode 100644 snippets/fsharp/System.Diagnostics/Process/StandardOutput/write500lines.fs create mode 100644 snippets/fsharp/System.Diagnostics/Process/Start/fs.fsproj create mode 100644 snippets/fsharp/System.Diagnostics/Process/Start/program.fs create mode 100644 snippets/fsharp/System.Diagnostics/Process/SynchronizingObject/fs.fsproj create mode 100644 snippets/fsharp/System.Diagnostics/Process/SynchronizingObject/remarks.fs create mode 100644 snippets/fsharp/System.Diagnostics/Process/WorkingSet/fs.fsproj create mode 100644 snippets/fsharp/System.Diagnostics/Process/WorkingSet/process_sample.fs diff --git a/snippets/fsharp/System.Diagnostics/DataReceivedEventArgs/Overview/datareceivedevent.fs b/snippets/fsharp/System.Diagnostics/DataReceivedEventArgs/Overview/datareceivedevent.fs new file mode 100644 index 00000000000..eda9e7d0eaf --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/DataReceivedEventArgs/Overview/datareceivedevent.fs @@ -0,0 +1,39 @@ +module datareceivedevent +// +open System +open System.Diagnostics +open System.Text + +let mutable lineCount = 0 +let output = StringBuilder() + +let proc = new Process() +proc.StartInfo.FileName <- "ipconfig.exe" +proc.StartInfo.UseShellExecute <- false +proc.StartInfo.RedirectStandardOutput <- true + +proc.OutputDataReceived.AddHandler( + DataReceivedEventHandler(fun _ e -> + // Prepend line numbers to each line of the output. + if not (String.IsNullOrEmpty e.Data) then + lineCount <- lineCount + 1 + output.Append $"\n[{lineCount}]: {e.Data}" |> ignore) +) + + +proc.Start() |> ignore + +// Asynchronously read the standard output of the spawned process. +// This raises OutputDataReceived events for each line of output. +proc.BeginOutputReadLine() +proc.WaitForExit() + +// Write the redirected output to this application's window. +printfn $"{output}" + +proc.WaitForExit() +proc.Close() + +printfn "\n\nPress any key to exit." +stdin.ReadLine() |> ignore +// diff --git a/snippets/fsharp/System.Diagnostics/DataReceivedEventArgs/Overview/fs.fsproj b/snippets/fsharp/System.Diagnostics/DataReceivedEventArgs/Overview/fs.fsproj new file mode 100644 index 00000000000..a76b5b40235 --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/DataReceivedEventArgs/Overview/fs.fsproj @@ -0,0 +1,13 @@ + + + Exe + net8.0 + + + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Diagnostics/DataReceivedEventArgs/Overview/net_async.fs b/snippets/fsharp/System.Diagnostics/DataReceivedEventArgs/Overview/net_async.fs new file mode 100644 index 00000000000..4a6df39ee9f --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/DataReceivedEventArgs/Overview/net_async.fs @@ -0,0 +1,156 @@ +module netasync +// System.Diagnostics +// +// Requires .NET Framework version 1.2 or higher. + +// The following example uses the net view command to list the +// available network resources available on a remote computer, +// and displays the results to the console. Specifying the optional +// error log file redirects error output to that file. + +// +// Define the namespaces used by this sample. +open System +open System.Text +open System.Globalization +open System.IO +open System.Diagnostics + +// Define variables shared by functions. +let mutable streamError = Unchecked.defaultof +let mutable netErrorFile = "" +let mutable netOutput = StringBuilder() +let mutable errorRedirect = false +let mutable errorsWritten = false + +let netOutputDataHandler (sendingProcess: obj) (outLine: DataReceivedEventArgs) = + // Collect the net view command output. + if String.IsNullOrEmpty outLine.Data |> not then + // Add the text to the collected output. + netOutput.Append(Environment.NewLine + " " + outLine.Data) |> ignore + +let netErrorDataHandler (sendingProcess: obj) (errLine: DataReceivedEventArgs) = + // Write the error text to the file if there is something + // to write and an error file has been specified. + + if String.IsNullOrEmpty errLine.Data |> not then + if not errorsWritten then + if isNull streamError then + // Open the file. + try + streamError <- new StreamWriter(netErrorFile, true) + with e -> + printfn "Could not open error file!" + printfn $"{e.Message}" + + if isNull streamError |> not then + // Write a header to the file if this is the first + // call to the error output handler. + streamError.WriteLine() + streamError.WriteLine DateTime.Now + streamError.WriteLine "Net View error output:" + + errorsWritten <- true + + if isNull streamError |> not then + // Write redirected errors to the file. + streamError.WriteLine errLine.Data + streamError.Flush() + + +let redirectNetCommandStreams () = + // Get the input computer name. + printfn "Enter the computer name for the net view command:" + let netArguments = stdin.ReadLine().ToUpper CultureInfo.InvariantCulture + // Default to the help command if there is not an input argument. + let netArguments = + if String.IsNullOrEmpty netArguments then + "/?" + else + netArguments + + // Check if errors should be redirected to a file. + errorsWritten <- false + printfn "Enter a fully qualified path to an error log file" + printfn " or just press Enter to write errors to console:" + netErrorFile <- stdin.ReadLine().ToUpper CultureInfo.InvariantCulture + + if String.IsNullOrEmpty netErrorFile |> not then + errorRedirect <- true + + // Note that at this point, netArguments and netErrorFile + // are set with user input. If the user did not specify + // an error file, then errorRedirect is set to false. + + // Initialize the process and its StartInfo properties. + let netProcess = new Process() + netProcess.StartInfo.FileName <- "Net.exe" + + // Build the net command argument list. + netProcess.StartInfo.Arguments <- $"view {netArguments}" + + // Set UseShellExecute to false for redirection. + netProcess.StartInfo.UseShellExecute <- false + + // Redirect the standard output of the net command. + // This stream is read asynchronously using an event handler. + netProcess.StartInfo.RedirectStandardOutput <- true + netProcess.OutputDataReceived.AddHandler(DataReceivedEventHandler netOutputDataHandler) + netOutput <- new StringBuilder() + + if errorRedirect then + // Redirect the error output of the net command. + netProcess.StartInfo.RedirectStandardError <- true + netProcess.ErrorDataReceived.AddHandler(DataReceivedEventHandler netErrorDataHandler) + else + // Do not redirect the error output. + netProcess.StartInfo.RedirectStandardError <- false + + printfn $"\nStarting process: net {netProcess.StartInfo.Arguments}" + + if errorRedirect then + printfn $"Errors will be written to the file {netErrorFile}" + + // Start the process. + netProcess.Start() |> ignore + + // Start the asynchronous read of the standard output stream. + netProcess.BeginOutputReadLine() + + if errorRedirect then + // Start the asynchronous read of the standard error stream. + netProcess.BeginErrorReadLine() + + // Let the net command run, collecting the output. + netProcess.WaitForExit() + + if streamError <> null then + // Close the error file. + streamError.Close() + else + // Set errorsWritten to false if the stream is not + // open. Either there are no errors, or the error + // file could not be opened. + errorsWritten <- false + + if netOutput.Length > 0 then + // If the process wrote more than just + // white space, write the output to the console. + printfn $"\nPublic network shares from net view:\n{netOutput}\n" + + if errorsWritten then + // Signal that the error file had something + // written to it. + let errorOutput = File.ReadAllLines netErrorFile + + if errorOutput.Length > 0 then + printfn $"\nThe following error output was appended to {netErrorFile}." + + for errLine in errorOutput do + printfn $" {errLine}" + + printfn "" + + netProcess.Close() + +// diff --git a/snippets/fsharp/System.Diagnostics/DataReceivedEventArgs/Overview/nmake_async.fs b/snippets/fsharp/System.Diagnostics/DataReceivedEventArgs/Overview/nmake_async.fs new file mode 100644 index 00000000000..ee5220c9a34 --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/DataReceivedEventArgs/Overview/nmake_async.fs @@ -0,0 +1,178 @@ +module nmakeasync +// System.Diagnostics +// +// Requires .NET Framework version 1.2 or higher. + +// Define the namespaces used by this sample. +open System +open System.Text +open System.IO +open System.Diagnostics +open System.Threading + +// +// Define static variables shared by class methods. +let mutable buildLogStream = Unchecked.defaultof +let logMutex = new Mutex() +let mutable maxLogLines = 25 +let mutable currentLogLines = 0 + +let logToFile logPrefix logText echoToConsole = + // Write the specified line to the log file stream. + let logString = StringBuilder() + + if String.IsNullOrEmpty logPrefix |> not then + logString.AppendFormat $"{logPrefix}> " |> ignore + + if String.IsNullOrEmpty logPrefix |> not then + logString.AppendFormat $"{logPrefix}> " |> ignore + + if String.IsNullOrEmpty logText |> not then + logString.Append logText |> ignore + + if isNull buildLogStream |> not then + buildLogStream.WriteLine $"[{DateTime.Now}] {logString}" + buildLogStream.Flush() + + if echoToConsole then + printfn $"{logString}" + +let nMakeOutputDataHandler (sendingProcess: obj) (outLine: DataReceivedEventArgs) = + // Collect the output, displaying it to the screen and + // logging it to the output file. Cancel the read + // operation when the maximum line limit is reached. + if String.IsNullOrEmpty outLine.Data |> not then + logMutex.WaitOne() |> ignore + + currentLogLines <- currentLogLines + 1 + + if currentLogLines > maxLogLines then + // Display the line to the console. + // Skip writing the line to the log file. + Console.WriteLine("StdOut: {0}", outLine.Data) + elif currentLogLines = maxLogLines then + logToFile "StdOut" "" true + + // Stop reading the output streams. + match sendingProcess with + | :? Process as p -> + p.CancelOutputRead() + p.CancelErrorRead() + | _ -> () + else + // Write the line to the log file. + logToFile "StdOut" outLine.Data true + + logMutex.ReleaseMutex() + +let nMakeErrorDataHandler (sendingProcess: obj) (errLine: DataReceivedEventArgs) = + // Collect error output, displaying it to the screen and + // logging it to the output file. Cancel the error output + // read operation when the maximum line limit is reached. + if String.IsNullOrEmpty errLine.Data |> not then + logMutex.WaitOne() |> ignore + + currentLogLines <- currentLogLines + 1 + + if currentLogLines > maxLogLines then + // Display the error line to the console. + // Skip writing the line to the log file. + printfn $"StdErr: {errLine.Data}" + elif currentLogLines = maxLogLines then + logToFile "StdErr" "" true + + // Stop reading the output streams + match sendingProcess with + | :? Process as p -> + p.CancelErrorRead() + p.CancelOutputRead() + | _ -> () + else + // Write the line to the log file. + logToFile "StdErr" errLine.Data true + + logMutex.ReleaseMutex() + +let redirectNMakeCommandStreams () = + // Get the input nmake command-line arguments. + printfn "Enter the NMake command line arguments (@commandfile or /f makefile, etc):" + let nmakeArguments = stdin.ReadLine() + + printfn "Enter max line limit for log file (default is 25):" + let inputText = Console.ReadLine() + + if String.IsNullOrEmpty inputText |> not then + if Int32.TryParse(inputText, &maxLogLines) |> not then + maxLogLines <- 25 + + printfn $"Output beyond {maxLogLines} lines will be ignored." + + // Initialize the process and its StartInfo properties. + let nmakeProcess = new Process() + nmakeProcess.StartInfo.FileName <- "NMake.exe" + + // Build the nmake command argument list. + if String.IsNullOrEmpty nmakeArguments |> not then + nmakeProcess.StartInfo.Arguments <- nmakeArguments + + // Set UseShellExecute to false for redirection. + nmakeProcess.StartInfo.UseShellExecute <- false + + // Redirect the standard output of the nmake command. + // Read the stream asynchronously using an event handler. + nmakeProcess.StartInfo.RedirectStandardOutput <- true + nmakeProcess.OutputDataReceived.AddHandler(DataReceivedEventHandler nMakeOutputDataHandler) + + // Redirect the error output of the nmake command. + nmakeProcess.StartInfo.RedirectStandardError <- true + nmakeProcess.ErrorDataReceived.AddHandler(DataReceivedEventHandler nMakeErrorDataHandler) + + logMutex.WaitOne() |> ignore + + currentLogLines <- 0 + + // Write a header to the log file. + let buildLogFile = "NmakeCmd.Txt" + + try + buildLogStream <- new StreamWriter(buildLogFile, true) + with e -> + printfn $"Could not open output file {buildLogFile}" + printfn $"Exception = {e}" + printfn $"{e.Message}" + + buildLogStream <- null + + if isNull buildLogStream |> not then + printfn $"Nmake output logged to {buildLogFile}" + + buildLogStream.WriteLine() + buildLogStream.WriteLine DateTime.Now + + if String.IsNullOrEmpty nmakeArguments |> not then + buildLogStream.Write $"Command line = NMake {nmakeArguments}" + else + buildLogStream.Write "Command line = Nmake" + + buildLogStream.WriteLine() + buildLogStream.Flush() + + logMutex.ReleaseMutex() + + // Start the process. + Console.WriteLine("\n\nStarting Nmake command...\n") + nmakeProcess.Start() |> ignore + + // Start the asynchronous read of the error stream. + nmakeProcess.BeginErrorReadLine() + + // Start the asynchronous read of the output stream. + nmakeProcess.BeginOutputReadLine() + + // Let the nmake command run, collecting the output. + nmakeProcess.WaitForExit() + + nmakeProcess.Close() + buildLogStream.Close() + logMutex.Dispose() +// diff --git a/snippets/fsharp/System.Diagnostics/DataReceivedEventArgs/Overview/sort_async.fs b/snippets/fsharp/System.Diagnostics/DataReceivedEventArgs/Overview/sort_async.fs new file mode 100644 index 00000000000..135a8d86d10 --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/DataReceivedEventArgs/Overview/sort_async.fs @@ -0,0 +1,97 @@ +module sortasync +// System.Diagnostics +// +// Requires .NET Framework version 1.2 or higher. + +// The following example uses the sort command to sort a list +// of input text lines, and displays the sorted list to the console. + +// +// Define the namespaces used by this sample. +open System +open System.Text +open System.Diagnostics + +// Define variables shared by class methods. +let mutable sortOutput = StringBuilder() +let mutable numOutputLines = 0; + +let sortOutputHandler (sendingProcess: obj) (outLine: DataReceivedEventArgs) = + // Collect the sort command output. + if String.IsNullOrEmpty outLine.Data |> not then + numOutputLines <- numOutputLines + 1 + // Add the text to the collected output. + sortOutput.Append(Environment.NewLine + $"[{numOutputLines}] - {outLine.Data}") |> ignore + +let sortInputListText () = + // Initialize the process and its StartInfo properties. + // The sort command is a console application that + // reads and sorts text input. + + let sortProcess = new Process(); + sortProcess.StartInfo.FileName <- "Sort.exe" + + // Set UseShellExecute to false for redirection. + sortProcess.StartInfo.UseShellExecute <- false; + + // Redirect the standard output of the sort command. + // This stream is read asynchronously using an event handler. + sortProcess.StartInfo.RedirectStandardOutput <- true; + sortOutput <- StringBuilder(); + + // Set our event handler to asynchronously read the sort output. + sortProcess.OutputDataReceived.AddHandler sortOutputHandler + + // Redirect standard input as well. This stream + // is used synchronously. + sortProcess.StartInfo.RedirectStandardInput <- true; + + // Start the process. + sortProcess.Start() |> ignore + + // Use a stream writer to synchronously write the sort input. + let sortStreamWriter = sortProcess.StandardInput; + + // Start the asynchronous read of the sort output stream. + sortProcess.BeginOutputReadLine(); + + // Prompt the user for input text lines. Write each + // line to the redirected input stream of the sort command. + printfn "Ready to sort up to 50 lines of text" + + let mutable inputText = "" + let mutable numInputLines = 0 + while String.IsNullOrEmpty inputText do + printfn "Enter a text line (or press the Enter key to stop):" + + inputText <- Console.ReadLine() + if String.IsNullOrEmpty inputText |> not then + numInputLines <- numInputLines + 1 + sortStreamWriter.WriteLine inputText + + printfn "\n" + + // End the input stream to the sort command. + sortStreamWriter.Close() + + // Wait for the sort process to write the sorted text lines. + sortProcess.WaitForExit() + + if numOutputLines > 0 then + // Write the formatted and sorted output to the console. + printfn $" Sort results = {numOutputLines} sorted text line(s) " + printfn "----------" + printfn $"{sortOutput}" + else + printfn " No input lines were sorted." + + sortProcess.Close(); + +// The main entry point for the application. +do + try + sortInputListText () + with :? InvalidOperationException as e -> + printfn "Exception:" + printfn $"{e}" +// diff --git a/snippets/fsharp/System.Diagnostics/Process/BasePriority/fs.fsproj b/snippets/fsharp/System.Diagnostics/Process/BasePriority/fs.fsproj new file mode 100644 index 00000000000..02825a27616 --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/BasePriority/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Diagnostics/Process/BasePriority/source.fs b/snippets/fsharp/System.Diagnostics/Process/BasePriority/source.fs new file mode 100644 index 00000000000..be04dae18a8 --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/BasePriority/source.fs @@ -0,0 +1,58 @@ +// The following example starts an instance of Notepad. The example +// then retrieves and displays various properties of the associated +// process. The example detects when the process exits, and displays +// the process's exit code. + +// +open System.Diagnostics + +// Define variables to track the peak +// memory usage of the process. +let mutable peakPagedMem = 0L +let mutable peakWorkingSet = 0L +let mutable peakVirtualMem = 0L + +// Start the process. +use myProcess = Process.Start "NotePad.exe" + +// Display the process statistics until +// the user closes the program. +while myProcess.WaitForExit 1000 |> not do + if not myProcess.HasExited then + // Refresh the current process property values. + myProcess.Refresh() + + printfn "" + + // Display current process statistics. + + printfn $"{myProcess} -" + printfn "-------------------------------------" + + printfn $" Physical memory usage : {myProcess.WorkingSet64}" + printfn $" Base priority : {myProcess.BasePriority}" + printfn $" Priority class : {myProcess.PriorityClass}" + printfn $" User processor time : {myProcess.UserProcessorTime}" + printfn $" Privileged processor time : {myProcess.PrivilegedProcessorTime}" + printfn $" Total processor time : {myProcess.TotalProcessorTime}" + printfn $" Paged system memory size : {myProcess.PagedSystemMemorySize64}" + printfn $" Paged memory size : {myProcess.PagedMemorySize64}" + + // Update the values for the overall peak memory statistics. + peakPagedMem <- myProcess.PeakPagedMemorySize64 + peakVirtualMem <- myProcess.PeakVirtualMemorySize64 + peakWorkingSet <- myProcess.PeakWorkingSet64 + + if myProcess.Responding then + printfn "Status = Running" + else + printfn "Status = Not Responding" + +printfn "" +printfn $" Process exit code : {myProcess.ExitCode}" + +// Display peak memory statistics for the process. +printfn $" Peak physical memory usage : {peakWorkingSet}" +printfn $" Peak paged memory usage : {peakPagedMem}" +printfn $" Peak virtual memory usage : {peakVirtualMem}" +// diff --git a/snippets/fsharp/System.Diagnostics/Process/Close/fs.fsproj b/snippets/fsharp/System.Diagnostics/Process/Close/fs.fsproj new file mode 100644 index 00000000000..73f309a09ea --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/Close/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Diagnostics/Process/Close/process_refresh.fs b/snippets/fsharp/System.Diagnostics/Process/Close/process_refresh.fs new file mode 100644 index 00000000000..7faf5f3d035 --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/Close/process_refresh.fs @@ -0,0 +1,42 @@ +// System.Diagnostics.Process.Refresh +// System.Diagnostics.Process.HasExited +// System.Diagnostics.Process.Close +// System.Diagnostics.Process.CloseMainWindow + +// The following example starts an instance of Notepad. It then +// retrieves the physical memory usage of the associated process at +// 2 second intervals for a maximum of 10 seconds. The example detects +// whether the process exits before 10 seconds have elapsed. +// The example closes the process if it is still running after +// 10 seconds. + +// +open System.ComponentModel +open System.Diagnostics +open System.IO +open System.Threading + + +try + use myProcess = Process.Start "Notepad.exe" + // Display physical memory usage 5 times at intervals of 2 seconds. + let mutable i = 0 + + while i < 5 && not myProcess.HasExited do + // Discard cached information about the process. + myProcess.Refresh() + // Print working set to console. + printfn $"Physical Memory Usage: {myProcess.WorkingSet64}" + // Wait 2 seconds. + Thread.Sleep 2000 + i <- i + 1 + // Close process by sending a close message to its main window. + myProcess.CloseMainWindow() |> ignore + // Free resources associated with process. + myProcess.Close() +with +| :? Win32Exception +| :? FileNotFoundException as e -> + printfn "The following exception was raised: " + printfn $"{e.Message}" +// diff --git a/snippets/fsharp/System.Diagnostics/Process/EnableRaisingEvents/fs.fsproj b/snippets/fsharp/System.Diagnostics/Process/EnableRaisingEvents/fs.fsproj new file mode 100644 index 00000000000..775b81171a9 --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/EnableRaisingEvents/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Diagnostics/Process/EnableRaisingEvents/processexitedevent.fs b/snippets/fsharp/System.Diagnostics/Process/EnableRaisingEvents/processexitedevent.fs new file mode 100644 index 00000000000..80905cd2724 --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/EnableRaisingEvents/processexitedevent.fs @@ -0,0 +1,49 @@ +// +open System +open System.Diagnostics +open System.Threading.Tasks + +let mutable myProcess = new Process() +let mutable eventHandled = TaskCompletionSource() + +// Handle Exited event and display process information. +let myProcess_Exited (sender: obj) (e: EventArgs) = + printfn $"Exit time : {myProcess.ExitTime}\n" + printfn $"Exit code : {myProcess.ExitCode}\n" + printfn $"Elapsed time : {round ((myProcess.ExitTime - myProcess.StartTime).TotalMilliseconds)}" + eventHandled.TrySetResult true |> ignore + +// Print a file with any known extension. +let printDoc fileName = + task { + eventHandled <- TaskCompletionSource() + + use myProcess = new Process() + + try + // Start a process to print a file and raise an event when done. + myProcess.StartInfo.FileName <- fileName + myProcess.StartInfo.Verb <- "Print" + myProcess.StartInfo.CreateNoWindow <- true + myProcess.EnableRaisingEvents <- true + myProcess.Exited.AddHandler(EventHandler myProcess_Exited) + myProcess.Start() |> ignore + with ex -> + printfn $"An error occurred trying to print \"{fileName}\":\n{ex.Message}" + + // Wait for Exited event, but not more than 30 seconds. + let! _ = Task.WhenAny(eventHandled.Task, Task.Delay(30000)) + () + } + +[] +let main args = + // Verify that an argument has been entered. + if args.Length <= 0 then + printfn "Enter a file name." + else + // Create the process and print the document. + printDoc(args[0]).Wait() |> ignore + + 0 +// diff --git a/snippets/fsharp/System.Diagnostics/Process/GetCurrentProcess/fs.fsproj b/snippets/fsharp/System.Diagnostics/Process/GetCurrentProcess/fs.fsproj new file mode 100644 index 00000000000..3aecc69ca32 --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/GetCurrentProcess/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Diagnostics/Process/GetCurrentProcess/processstaticget.fs b/snippets/fsharp/System.Diagnostics/Process/GetCurrentProcess/processstaticget.fs new file mode 100644 index 00000000000..a7d50a84b06 --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/GetCurrentProcess/processstaticget.fs @@ -0,0 +1,34 @@ +// +open System.Diagnostics + +// Get the current process. +let currentProcess = Process.GetCurrentProcess() + +// Get all processes running on the local computer. +let localAll = Process.GetProcesses() + +// Get all instances of Notepad running on the local computer. +// This will return an empty array if notepad isn't running. +let localByName = Process.GetProcessesByName "notepad" + +// Get a process on the local computer, using the process id. +// This will throw an exception if there is no such process. +let localById = Process.GetProcessById 1234 + +// Get processes running on a remote computer. Note that this +// and all the following calls will timeout and throw an exception +// if "myComputer" and 169.0.0.0 do not exist on your local network. + +// Get all processes on a remote computer. +let remoteAll = Process.GetProcesses "myComputer" + +// Get all instances of Notepad running on the specific computer, using machine name. +let remoteByName = Process.GetProcessesByName("notepad", "myComputer") + +// Get all instances of Notepad running on the specific computer, using IP address. +let ipByName = Process.GetProcessesByName("notepad", "169.0.0.0") + +// Get a process on a remote computer, using the process id and machine name. +let remoteById = Process.GetProcessById(2345, "myComputer") + +// diff --git a/snippets/fsharp/System.Diagnostics/Process/Id/fs.fsproj b/snippets/fsharp/System.Diagnostics/Process/Id/fs.fsproj new file mode 100644 index 00000000000..bdaff5e1367 --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/Id/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Diagnostics/Process/Id/program.fs b/snippets/fsharp/System.Diagnostics/Process/Id/program.fs new file mode 100644 index 00000000000..cef03db5c6d --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/Id/program.fs @@ -0,0 +1,38 @@ +// +open System +open System.Diagnostics + +let notePad = Process.Start "notepad" +printfn $"Started notepad process Id = {notePad.Id}" +printfn "All instances of notepad:" +// Get Process objects for all running instances on notepad. +let localByName = Process.GetProcessesByName "notepad" +let mutable i = localByName.Length + +while i > 0 do + // You can use the process Id to pass to other applications or to + // reference that particular instance of the application. + printfn $"{localByName.[i - 1].Id}" + i <- i - 1 + +i <- localByName.Length + +while i > 0 do + printfn "Enter a process Id to kill the process" + let id = Console.ReadLine() + + if String.IsNullOrEmpty id then + i <- 0 + else + try + use chosen = Int32.Parse id |> Process.GetProcessById + + if chosen.ProcessName = "notepad" then + chosen.Kill() + chosen.WaitForExit() + + i <- i - 1 + with e -> + printfn "Incorrect entry." + +// diff --git a/snippets/fsharp/System.Diagnostics/Process/MachineName/fs.fsproj b/snippets/fsharp/System.Diagnostics/Process/MachineName/fs.fsproj new file mode 100644 index 00000000000..8d59b67ca9a --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/MachineName/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Diagnostics/Process/MachineName/process_getprocessesbyname2_2.fs b/snippets/fsharp/System.Diagnostics/Process/MachineName/process_getprocessesbyname2_2.fs new file mode 100644 index 00000000000..6ee5fd2f82a --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/MachineName/process_getprocessesbyname2_2.fs @@ -0,0 +1,31 @@ +// +// +open System +open System.Diagnostics + +printfn "Create notepad processes on remote computer" +printf "Enter remote computer name : " +let remoteMachineName = stdin.ReadLine() + +if isNull remoteMachineName then + // Prepend a new line to prevent it from being on the same line as the prompt. + printfn "\nYou have to enter a remote computer name." +else + try + // Get all notepad processess into Process array. + let myProcesses = Process.GetProcessesByName("notepad", remoteMachineName) + + if myProcesses.Length = 0 then + printfn "Could not find notepad processes on remote computer." + + for myProcess in myProcesses do + printfn $"Process Name : {myProcess.ProcessName}\n" + printfn $"Process ID : {myProcess.Id}\n" + printfn $"MachineName : {myProcess.MachineName}" + with + | :? ArgumentException -> printfn $"The value '{remoteMachineName}' is an invalid remote computer name." + | :? InvalidOperationException -> printfn "Unable to get process information on the remote computer." + | :? PlatformNotSupportedException -> + printfn "Finding notepad processes on remote computers is not supported on this operating system." +// +// diff --git a/snippets/fsharp/System.Diagnostics/Process/MainWindowTitle/fs.fsproj b/snippets/fsharp/System.Diagnostics/Process/MainWindowTitle/fs.fsproj new file mode 100644 index 00000000000..592dff3dfd7 --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/MainWindowTitle/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Diagnostics/Process/MainWindowTitle/process_mainwindowtitle.fs b/snippets/fsharp/System.Diagnostics/Process/MainWindowTitle/process_mainwindowtitle.fs new file mode 100644 index 00000000000..8bf403fa9f4 --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/MainWindowTitle/process_mainwindowtitle.fs @@ -0,0 +1,20 @@ +// +open System.Diagnostics + +try + // Create an instance of process component. + use myProcess = new Process() + // Create an instance of 'myProcessStartInfo'. + let myProcessStartInfo = ProcessStartInfo() + myProcessStartInfo.FileName <- "notepad" + myProcess.StartInfo <- myProcessStartInfo + // Start process. + myProcess.Start() |> ignore + // Allow the process to finish starting. + myProcess.WaitForInputIdle() |> ignore + printfn $"Main window Title : {myProcess.MainWindowTitle}" + + myProcess.CloseMainWindow() |> ignore +with e -> + printfn $" Message : {e.Message}" +// diff --git a/snippets/fsharp/System.Diagnostics/Process/OnExited/fs.fsproj b/snippets/fsharp/System.Diagnostics/Process/OnExited/fs.fsproj new file mode 100644 index 00000000000..bdaff5e1367 --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/OnExited/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Diagnostics/Process/OnExited/program.fs b/snippets/fsharp/System.Diagnostics/Process/OnExited/program.fs new file mode 100644 index 00000000000..a94790e9e56 --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/OnExited/program.fs @@ -0,0 +1,23 @@ +// +open System +open System.Diagnostics + +type MyProcess() = + inherit Process() + + member this.Stop() = + this.CloseMainWindow() |> ignore + this.Close() + this.OnExited() + +let myProcess_HasExited (sender: obj) (e: EventArgs) = printfn "Process has exited." + +let p = new MyProcess() +p.StartInfo.FileName <- "notepad.exe" +p.EnableRaisingEvents <- true +p.Exited.AddHandler(EventHandler myProcess_HasExited) +p.Start() |> ignore +p.WaitForInputIdle() |> ignore +p.Stop() + +// diff --git a/snippets/fsharp/System.Diagnostics/Process/Overview/fs.fsproj b/snippets/fsharp/System.Diagnostics/Process/Overview/fs.fsproj new file mode 100644 index 00000000000..7e6b5cd5a33 --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/Overview/fs.fsproj @@ -0,0 +1,11 @@ + + + Exe + net8.0 + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Diagnostics/Process/Overview/processstart.fs b/snippets/fsharp/System.Diagnostics/Process/Overview/processstart.fs new file mode 100644 index 00000000000..88bf0d1c62f --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/Overview/processstart.fs @@ -0,0 +1,19 @@ +module processstart +// +open System.Diagnostics + +try + use myProcess = new Process() + myProcess.StartInfo.UseShellExecute <- false + // You can start any process, HelloWorld is a do-nothing example. + myProcess.StartInfo.FileName <- @"C:\HelloWorld.exe" + myProcess.StartInfo.CreateNoWindow <- true + myProcess.Start() |> ignore +// This code assumes the process you are starting will terminate itself. +// Given that it is started without a window so you cannot terminate it +// on the desktop, it must terminate itself or you can do it programmatically +// from this application using the Kill method. +with e -> + printfn $"{e.Message}" + +// diff --git a/snippets/fsharp/System.Diagnostics/Process/Overview/processstartstatic.fs b/snippets/fsharp/System.Diagnostics/Process/Overview/processstartstatic.fs new file mode 100644 index 00000000000..0216c8c3afb --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/Overview/processstartstatic.fs @@ -0,0 +1,41 @@ +module processstartstatic + +open System +open System.Diagnostics + +// Opens the Internet Explorer application. +let openApplication (myFavoritesPath: string) = + // Start Internet Explorer. Defaults to the home page. + Process.Start "IExplore.exe" |> ignore + + // Display the contents of the favorites folder in the browser. + Process.Start myFavoritesPath |> ignore + +// Opens urls and .html documents using Internet Explorer. +let openWithArguments () = + // url's are not considered documents. They can only be opened + // by passing them as arguments. + Process.Start("IExplore.exe", "www.northwindtraders.com") |> ignore + + // Start a Web page using a browser associated with .html and .asp files. + Process.Start("IExplore.exe", @"C:\myPath\myFile.htm") |> ignore + Process.Start("IExplore.exe", @"C:\myPath\myFile.asp") |> ignore + +// Uses the ProcessStartInfo class to start new processes, +// both in a minimized mode. +let openWithStartInfo () = + let startInfo = ProcessStartInfo "IExplore.exe" + startInfo.WindowStyle <- ProcessWindowStyle.Minimized + + Process.Start startInfo |> ignore + + startInfo.Arguments <- "www.northwindtraders.com" + + Process.Start startInfo |> ignore + +// Get the path that stores favorite links. +let myFavoritesPath = Environment.GetFolderPath Environment.SpecialFolder.Favorites + +openApplication myFavoritesPath +openWithArguments () +openWithStartInfo () diff --git a/snippets/fsharp/System.Diagnostics/Process/StandardError/fs.fsproj b/snippets/fsharp/System.Diagnostics/Process/StandardError/fs.fsproj new file mode 100644 index 00000000000..f0ea1aedf67 --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/StandardError/fs.fsproj @@ -0,0 +1,11 @@ + + + Exe + net8.0 + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Diagnostics/Process/StandardError/source.fs b/snippets/fsharp/System.Diagnostics/Process/StandardError/source.fs new file mode 100644 index 00000000000..31dd7131772 --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/StandardError/source.fs @@ -0,0 +1,15 @@ +open System.Diagnostics +let args = [||] +// +use myProcess = new Process() +let myProcessStartInfo = ProcessStartInfo("net ", $"use {args[0]}") + +myProcessStartInfo.UseShellExecute <- false +myProcessStartInfo.RedirectStandardError <- true +myProcess.StartInfo <- myProcessStartInfo +myProcess.Start() |> ignore + +let myStreamReader = myProcess.StandardError +// Read the standard error of net.exe and write it on to console. +printfn $"{myStreamReader.ReadLine()}" +// diff --git a/snippets/fsharp/System.Diagnostics/Process/StandardError/stderror-sync.fs b/snippets/fsharp/System.Diagnostics/Process/StandardError/stderror-sync.fs new file mode 100644 index 00000000000..2ba2679fb74 --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/StandardError/stderror-sync.fs @@ -0,0 +1,18 @@ +module STDErrorSync + +open System.Diagnostics + +let p = new Process() +p.StartInfo.UseShellExecute <- false +p.StartInfo.RedirectStandardError <- true +p.StartInfo.FileName <- "Write500Lines.exe" +p.Start() |> ignore + +// To avoid deadlocks, always read the output stream first and then wait. +let output = p.StandardError.ReadToEnd() +p.WaitForExit() + +printfn $"\nError stream: {output}" +// The end of the output produced by the example includes the following: +// Error stream: +// Successfully wrote 500 lines. diff --git a/snippets/fsharp/System.Diagnostics/Process/StandardInput/fs.fsproj b/snippets/fsharp/System.Diagnostics/Process/StandardInput/fs.fsproj new file mode 100644 index 00000000000..9c042523086 --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/StandardInput/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Diagnostics/Process/StandardInput/process_standardinput.fs b/snippets/fsharp/System.Diagnostics/Process/StandardInput/process_standardinput.fs new file mode 100644 index 00000000000..6ea5ba4f190 --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/StandardInput/process_standardinput.fs @@ -0,0 +1,58 @@ +// System.Diagnostics.Process.StandardInput +// +// +// The following example illustrates how to redirect the StandardInput +// stream of a process. The example starts the sort command with +// redirected input. It then prompts the user for text, and passes +// that to the sort command by means of the redirected input stream. +// The sort command results are displayed to the user on the console. + +// +open System.Diagnostics + +printfn "Ready to sort one or more text lines..." + +// Start the Sort.exe process with redirected input. +// Use the sort command to sort the input text. +use myProcess = new Process() + +myProcess.StartInfo.FileName <- "Sort.exe" +myProcess.StartInfo.UseShellExecute <- false +myProcess.StartInfo.RedirectStandardInput <- true + +myProcess.Start() |> ignore + +let myStreamWriter = myProcess.StandardInput + +// Prompt the user for input text lines to sort. +// Write each line to the StandardInput stream of +// the sort command. + +let mutable inputText = "" +let mutable numLines = 0 + +while inputText.Length > 0 do + printfn "Enter a line of text (or press the Enter key to stop):" + + inputText <- stdin.ReadLine() + + if inputText.Length > 0 then + numLines <- numLines + 1 + myStreamWriter.WriteLine inputText + +// Write a report header to the console. +if numLines > 0 then + printfn $" {numLines} sorted text line(s) " + printfn "------------------------" +else + printfn $" No input was sorted" + +// End the input stream to the sort command. +// When the stream closes, the sort command +// writes the sorted text lines to the +// console. +myStreamWriter.Close() + +// Wait for the sort process to write the sorted text lines. +myProcess.WaitForExit() +// diff --git a/snippets/fsharp/System.Diagnostics/Process/StandardOutput/fs.fsproj b/snippets/fsharp/System.Diagnostics/Process/StandardOutput/fs.fsproj new file mode 100644 index 00000000000..8a1d11239fb --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/StandardOutput/fs.fsproj @@ -0,0 +1,13 @@ + + + Exe + net8.0 + + + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Diagnostics/Process/StandardOutput/process_standardoutput.fs b/snippets/fsharp/System.Diagnostics/Process/StandardOutput/process_standardoutput.fs new file mode 100644 index 00000000000..11bb7ae69e1 --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/StandardOutput/process_standardoutput.fs @@ -0,0 +1,21 @@ +module ProcessStandardOutput + +open System.Diagnostics + +use proc = new Process() +proc.StartInfo.FileName <- "ipconfig.exe" +proc.StartInfo.UseShellExecute <- false +proc.StartInfo.RedirectStandardOutput <- true +proc.Start() |> ignore + +// Synchronously read the standard output of the spawned process. +let reader = proc.StandardOutput +let output = reader.ReadToEnd() + +// Write the redirected output to this application's window. +printfn $"{output}" + +proc.WaitForExit() + +printfn "\n\nPress any key to exit." +stdin.ReadLine() |> ignore diff --git a/snippets/fsharp/System.Diagnostics/Process/StandardOutput/stdoutput-async.fs b/snippets/fsharp/System.Diagnostics/Process/StandardOutput/stdoutput-async.fs new file mode 100644 index 00000000000..3c7a78fd6c9 --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/StandardOutput/stdoutput-async.fs @@ -0,0 +1,28 @@ +module STDOutputAsync + +open System.Diagnostics + +let p = new Process() +p.StartInfo.UseShellExecute <- false +p.StartInfo.RedirectStandardOutput <- true +let mutable eOut = "" +p.StartInfo.RedirectStandardError <- true +p.ErrorDataReceived.AddHandler(DataReceivedEventHandler(fun sender e -> eOut <- eOut + e.Data)) + +p.StartInfo.FileName <- "Write500Lines.exe" +p.Start() |> ignore + +// To avoid deadlocks, use an asynchronous read operation on at least one of the streams. +p.BeginErrorReadLine() +let output = p.StandardOutput.ReadToEnd() +p.WaitForExit() + +printfn $"The last 50 characters in the output stream are:\n'{output.Substring(output.Length - 50)}'" +printfn $"\nError stream: {eOut}" +// The example displays the following output: +// The last 50 characters in the output stream are: +// ' 49,800.20% +// Line 500 of 500 written: 49,900.20% +// ' +// +// Error stream: Successfully wrote 500 lines. diff --git a/snippets/fsharp/System.Diagnostics/Process/StandardOutput/stdoutput-sync.fs b/snippets/fsharp/System.Diagnostics/Process/StandardOutput/stdoutput-sync.fs new file mode 100644 index 00000000000..e01ab27ddcb --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/StandardOutput/stdoutput-sync.fs @@ -0,0 +1,22 @@ +module STDOutputSync + +open System.Diagnostics + +let p = new Process() +p.StartInfo.UseShellExecute <- false +p.StartInfo.RedirectStandardOutput <- true +p.StartInfo.FileName <- "Write500Lines.exe" +p.Start() |> ignore + +// To avoid deadlocks, always read the output stream first and then wait. +let output = p.StandardOutput.ReadToEnd() +p.WaitForExit() + +printfn $"The last 50 characters in the output stream are:\n'{output.Substring(output.Length - 50)}'" +// The example displays the following output: +// Successfully wrote 500 lines. +// +// The last 50 characters in the output stream are: +// ' 49,800.20% +// Line 500 of 500 written: 49,900.20% +// ' diff --git a/snippets/fsharp/System.Diagnostics/Process/StandardOutput/write500lines.fs b/snippets/fsharp/System.Diagnostics/Process/StandardOutput/write500lines.fs new file mode 100644 index 00000000000..5053af9903a --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/StandardOutput/write500lines.fs @@ -0,0 +1,13 @@ +module Write500Lines + +for i in 1. .. 500. do + printfn $"Line {i} of 500 written: {i/500.:P2}"; + +eprintfn "Successfully wrote 500 lines."; +// The example displays the following output: +// The last 50 characters in the output stream are: +// ' 49,800.20% +// Line 500 of 500 written: 49,900.20% +//' +// +// Error stream: Successfully wrote 500 lines. diff --git a/snippets/fsharp/System.Diagnostics/Process/Start/fs.fsproj b/snippets/fsharp/System.Diagnostics/Process/Start/fs.fsproj new file mode 100644 index 00000000000..bdaff5e1367 --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/Start/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Diagnostics/Process/Start/program.fs b/snippets/fsharp/System.Diagnostics/Process/Start/program.fs new file mode 100644 index 00000000000..ec414573ffc --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/Start/program.fs @@ -0,0 +1,54 @@ +// +// NOTE: This example requires a text.txt file file in your Documents folder +open System +open System.Diagnostics +open System.Security +open System.ComponentModel + +printf "Enter your domain: " +let domain = stdin.ReadLine() +printf "Enter you user name: " +let uname = stdin.ReadLine() +printf "Enter your password: " +let password = new SecureString() + +let mutable key = Console.ReadKey(true) + +while key.Key <> ConsoleKey.Enter do + // Ignore any key out of range. + if int key.Key >= 33 && int key.Key <= 90 && key.Key <> ConsoleKey.Enter then + // Append the character to the password. + password.AppendChar key.KeyChar + Console.Write "*" + + key <- Console.ReadKey(true) + +printfn "" + +try + printfn "\nTrying to launch NotePad using your login information..." + Process.Start("notepad.exe", uname, password, domain) |> ignore +with :? Win32Exception as ex -> + printfn $"{ex.Message}" + +let path = Environment.GetFolderPath Environment.SpecialFolder.MyDocuments + @"\" + +try + // The following call to Start succeeds if test.txt exists. + printfn "\nTrying to launch 'text.txt'..." + Process.Start $"{path}text.txt" |> ignore +with :? Win32Exception as ex -> + printfn $"{ex.Message}" + +try + try + // Attempting to start in a shell using this Start overload fails. This causes + // the following exception, which is picked up in the catch block below: + // The specified executable is not a valid application for this OS platform. + printfn "\nTrying to launch 'text.txt' with your login information..." + Process.Start($"{path}text.txt", uname, password, domain) |> ignore + with :? Win32Exception as ex -> + printfn $"{ex.Message}" +finally + password.Dispose() +// diff --git a/snippets/fsharp/System.Diagnostics/Process/SynchronizingObject/fs.fsproj b/snippets/fsharp/System.Diagnostics/Process/SynchronizingObject/fs.fsproj new file mode 100644 index 00000000000..93fbd53a90a --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/SynchronizingObject/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Diagnostics/Process/SynchronizingObject/remarks.fs b/snippets/fsharp/System.Diagnostics/Process/SynchronizingObject/remarks.fs new file mode 100644 index 00000000000..f409250348c --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/SynchronizingObject/remarks.fs @@ -0,0 +1,12 @@ +module remarks + +let x (process1: System.Diagnostics.Process) this = + // + process1.StartInfo.Domain <- ""; + process1.StartInfo.LoadUserProfile <- false; + process1.StartInfo.Password <- null; + process1.StartInfo.StandardErrorEncoding <- null; + process1.StartInfo.StandardOutputEncoding <- null; + process1.StartInfo.UserName <- ""; + process1.SynchronizingObject <- this; + // \ No newline at end of file diff --git a/snippets/fsharp/System.Diagnostics/Process/WorkingSet/fs.fsproj b/snippets/fsharp/System.Diagnostics/Process/WorkingSet/fs.fsproj new file mode 100644 index 00000000000..5382e3af1c6 --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/WorkingSet/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Diagnostics/Process/WorkingSet/process_sample.fs b/snippets/fsharp/System.Diagnostics/Process/WorkingSet/process_sample.fs new file mode 100644 index 00000000000..9a0241c4ee4 --- /dev/null +++ b/snippets/fsharp/System.Diagnostics/Process/WorkingSet/process_sample.fs @@ -0,0 +1,46 @@ +// System.Diagnostics.Process.WorkingSet +// System.Diagnostics.Process.BasePriority +// System.Diagnostics.Process.UserProcessorTime +// System.Diagnostics.Process.PrivilegedProcessorTime +// System.Diagnostics.Process.TotalProcessorTime +// System.Diagnostics.Process.ToString +// System.Diagnostics.Process.Responding +// System.Diagnostics.Process.PriorityClass +// System.Diagnostics.Process.ExitCode + +// The following example starts an instance of Notepad. The example +// then retrieves and displays various properties of the associated +// process. The example detects when the process exits, and displays the process's exit code. + +// +open System.Diagnostics +open System.Threading + +try + use myProcess = Process.Start "NotePad.exe" + + while not myProcess.HasExited do + printfn "" + + printfn $"Physical memory usage : {myProcess.WorkingSet64}" + printfn $"Base priority : {myProcess.BasePriority}" + printfn $"Priority class : {myProcess.PriorityClass}" + printfn $"User processor time : {myProcess.UserProcessorTime}" + printfn $"Privileged processor time : {myProcess.PrivilegedProcessorTime}" + printfn $"Total processor time : {myProcess.TotalProcessorTime}" + printfn $"Process's Name : {myProcess}" + printfn "-------------------------------------" + + if myProcess.Responding then + printfn "Status: Responding to user interface" + myProcess.Refresh() + else + printfn "Status: Not Responding" + + Thread.Sleep 1000 + + printfn "" + printfn $"Process exit code: {myProcess.ExitCode}" +with e -> + printfn $"The following exception was raised: {e.Message}" +// diff --git a/xml/System.Diagnostics/Process.xml b/xml/System.Diagnostics/Process.xml index 90ef4d870d1..7000af75d69 100644 --- a/xml/System.Diagnostics/Process.xml +++ b/xml/System.Diagnostics/Process.xml @@ -134,12 +134,14 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Process.Start_instance/CPP/processstart.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/Process/Overview/processstart.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/Process/Overview/processstart.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Process.Start_instance/VB/processstart.vb" id="Snippet1"::: The following example uses the class itself and a static method to start a process. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Process.Start_static/CPP/processstartstatic.cpp"::: :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/Process/Overview/processstartstatic.cs"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/Process/Overview/processstartstatic.fs"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Process.Start_static/VB/processstartstatic.vb"::: The following F# example defines a `runProc` function that starts a process, captures all output and error information, and records the number of milliseconds that the process has run. The `runProc` function has three parameters: the name of application to launch, the arguments to supply to the application, and the starting directory. @@ -285,6 +287,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Diag_Process_MemoryProperties64/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/Process/BasePriority/source.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/Process/BasePriority/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Diag_Process_MemoryProperties64/VB/source.vb" id="Snippet1"::: ]]> @@ -376,6 +379,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/process_asyncstreams/CPP/net_async.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/DataReceivedEventArgs/Overview/net_async.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/DataReceivedEventArgs/Overview/net_async.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/process_asyncstreams/VB/net_async.vb" id="Snippet2"::: ]]> @@ -475,6 +479,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/process_asyncstreams/CPP/sort_async.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/DataReceivedEventArgs/Overview/sort_async.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/DataReceivedEventArgs/Overview/sort_async.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/process_asyncstreams/VB/sort_async.vb" id="Snippet1"::: ]]> @@ -574,6 +579,7 @@ process.BeginErrorReadLine(); :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/process_asyncstreams/CPP/nmake_async.cpp" id="Snippet3"::: :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/DataReceivedEventArgs/Overview/nmake_async.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/DataReceivedEventArgs/Overview/nmake_async.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/process_asyncstreams/VB/nmake_async.vb" id="Snippet3"::: ]]> @@ -665,6 +671,7 @@ process.BeginOutputReadLine(); :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/process_asyncstreams/CPP/nmake_async.cpp" id="Snippet3"::: :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/DataReceivedEventArgs/Overview/nmake_async.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/DataReceivedEventArgs/Overview/nmake_async.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/process_asyncstreams/VB/nmake_async.vb" id="Snippet3"::: ]]> @@ -730,6 +737,7 @@ process.BeginOutputReadLine(); :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/process_refresh/CPP/process_refresh.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/Process/Close/process_refresh.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/Process/Close/process_refresh.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/process_refresh/VB/process_refresh.vb" id="Snippet1"::: ]]> @@ -792,6 +800,7 @@ process.BeginOutputReadLine(); :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/process_refresh/CPP/process_refresh.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/Process/Close/process_refresh.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/Process/Close/process_refresh.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/process_refresh/VB/process_refresh.vb" id="Snippet1"::: ]]> @@ -961,6 +970,7 @@ Sometimes, your application starts a process but doesn't require notification of The following code example creates a process that prints a file. It sets the property to cause the process to raise the event when it exits. The event handler displays process information. :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/Process/EnableRaisingEvents/processexitedevent.cs" id="Snippet1"::: +:::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/Process/EnableRaisingEvents/processexitedevent.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Diagnostics.Process.EnableExited/VB/processexitedevent.vb" id="Snippet1"::: ]]> @@ -1101,6 +1111,7 @@ The following code example creates a process that prints a file. It sets the @@ -1190,6 +1201,7 @@ The following code example creates a process that prints a file. It sets the @@ -1275,6 +1287,7 @@ The following code example creates a process that prints a file. It sets the event when the process exits because the property was set when the process was created. The event handler displays process information. :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/Process/EnableRaisingEvents/processexitedevent.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/Process/EnableRaisingEvents/processexitedevent.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Diagnostics.Process.EnableExited/VB/processexitedevent.vb" id="Snippet1"::: ]]> @@ -1345,6 +1358,7 @@ The following code example creates a process that prints a file. It sets the event when it exits, and the event handler displays the property and other process information. :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/Process/EnableRaisingEvents/processexitedevent.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/Process/EnableRaisingEvents/processexitedevent.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Diagnostics.Process.EnableExited/VB/processexitedevent.vb" id="Snippet1"::: ]]> @@ -1408,6 +1422,7 @@ The following code example creates a process that prints a file. It sets the @@ -1490,6 +1505,7 @@ The following code example creates a process that prints a file. It sets the @@ -1562,6 +1578,7 @@ The following code example creates a process that prints a file. It sets the @@ -1664,6 +1681,7 @@ The following code example creates a process that prints a file. It sets the @@ -1750,6 +1768,7 @@ The following code example creates a process that prints a file. It sets the @@ -1860,6 +1879,7 @@ The following code example creates a process that prints a file. It sets the @@ -1958,6 +1978,7 @@ The following code example creates a process that prints a file. It sets the @@ -2189,6 +2210,7 @@ There are problems accessing the performance counter APIs used to get process in :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/process_refresh/CPP/process_refresh.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/Process/Close/process_refresh.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/Process/Close/process_refresh.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/process_refresh/VB/process_refresh.vb" id="Snippet1"::: ]]> @@ -2269,6 +2291,7 @@ There are problems accessing the performance counter APIs used to get process in The following example demonstrates how to obtain the for all running instances of an application. The code creates a new instance of Notepad, lists all the instances of Notepad, and then allows the user to enter the number to remove a specific instance. :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/Process/Id/program.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/Process/Id/program.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Diagnostics.Process.Id/VB/program.vb" id="Snippet1"::: ]]> @@ -2566,6 +2589,7 @@ The calling process is a member of the associated process's descendant tree., , and properties for each instance. :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/Process/MachineName/process_getprocessesbyname2_2.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/Process/MachineName/process_getprocessesbyname2_2.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Process_GetProcessesByName2_2/VB/process_getprocessesbyname2_2.vb" id="Snippet2"::: ]]> @@ -2787,6 +2811,7 @@ The calling process is a member of the associated process's descendant tree. @@ -3218,6 +3243,7 @@ The calling process is a member of the associated process's descendant tree. @@ -3282,6 +3308,7 @@ The calling process is a member of the associated process's descendant tree. method in a derived class. :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/Process/OnExited/program.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/Process/OnExited/program.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/onexitsample/vb/program.vb" id="Snippet1"::: ]]> @@ -3369,6 +3396,7 @@ The calling process is a member of the associated process's descendant tree. @@ -3511,6 +3539,7 @@ The calling process is a member of the associated process's descendant tree. @@ -3648,6 +3677,7 @@ The calling process is a member of the associated process's descendant tree. @@ -3785,6 +3815,7 @@ The calling process is a member of the associated process's descendant tree. @@ -3921,6 +3952,7 @@ The calling process is a member of the associated process's descendant tree. @@ -4071,6 +4103,7 @@ The calling process is a member of the associated process's descendant tree. @@ -4224,6 +4257,7 @@ The calling process is a member of the associated process's descendant tree. @@ -4369,6 +4403,7 @@ The calling process is a member of the associated process's descendant tree. @@ -4443,6 +4478,7 @@ The calling process is a member of the associated process's descendant tree. @@ -4667,6 +4703,7 @@ The calling process is a member of the associated process's descendant tree. @@ -4738,6 +4775,7 @@ The calling process is a member of the associated process's descendant tree. @@ -4936,15 +4974,18 @@ The calling process is a member of the associated process's descendant tree. method to launch an executable named *Write500Lines.exe*. The following example contains its source code. :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/Process/StandardOutput/write500lines.cs"::: +:::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/Process/StandardOutput/write500lines.fs"::: :::code language="vb" source="~/snippets/visualbasic/api/system.diagnostics/process/standardoutput/write500lines.vb"::: The following example shows how to read from a redirected error stream and wait for the child process to exit. It avoids a deadlock condition by calling `p.StandardError.ReadToEnd` before `p.WaitForExit`. A deadlock condition can result if the parent process calls `p.WaitForExit` before `p.StandardError.ReadToEnd` and the child process writes enough text to fill the redirected stream. The parent process would wait indefinitely for the child process to exit. The child process would wait indefinitely for the parent to read from the full stream. :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/Process/StandardError/stderror-sync.cs"::: +:::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/Process/StandardError/stderror-sync.fs"::: :::code language="vb" source="~/snippets/visualbasic/api/system.diagnostics/process/standarderror/stderror-sync.vb"::: There is a similar issue when you read all text from both the standard output and standard error streams. The following example performs a read operation on both streams. It avoids the deadlock condition by performing asynchronous read operations on the stream. A deadlock condition results if the parent process calls `p.StandardOutput.ReadToEnd` followed by `p.StandardError.ReadToEnd` and the child process writes enough text to fill its error stream. The parent process would wait indefinitely for the child process to close its stream. The child process would wait indefinitely for the parent to read from the full stream. :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/Process/StandardOutput/stdoutput-async.cs"::: +:::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/Process/StandardOutput/stdoutput-async.fs"::: :::code language="vb" source="~/snippets/visualbasic/api/system.diagnostics/process/standardoutput/stdoutput-async.vb"::: You can use asynchronous read operations to avoid these dependencies and their deadlock potential. Alternately, you can avoid the deadlock condition by creating two threads and reading the output of each stream on a separate thread. @@ -4959,6 +5000,7 @@ You can use asynchronous read operations to avoid these dependencies and their d :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Process_StandardError/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/Process/StandardError/source.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/Process/StandardError/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Process_StandardError/VB/source.vb" id="Snippet1"::: ]]> @@ -5041,6 +5083,7 @@ You can use asynchronous read operations to avoid these dependencies and their d :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Process_StandardInput/CPP/process_standardinput.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/Process/StandardInput/process_standardinput.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/Process/StandardInput/process_standardinput.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Process_StandardInput/VB/process_standardinput.vb" id="Snippet1"::: ]]> @@ -5121,15 +5164,18 @@ You can use asynchronous read operations to avoid these dependencies and their d The last two examples in this section use the method to launch an executable named *Write500Lines.exe*. The following example contains its source code. :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/Process/StandardOutput/write500lines.cs"::: +:::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/Process/StandardOutput/write500lines.fs"::: :::code language="vb" source="~/snippets/visualbasic/api/system.diagnostics/process/standardoutput/write500lines.vb"::: The following example shows how to read from a redirected stream and wait for the child process to exit. The example avoids a deadlock condition by calling `p.StandardOutput.ReadToEnd` before `p.WaitForExit`. A deadlock condition can result if the parent process calls `p.WaitForExit` before `p.StandardOutput.ReadToEnd` and the child process writes enough text to fill the redirected stream. The parent process would wait indefinitely for the child process to exit. The child process would wait indefinitely for the parent to read from the full stream. :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/Process/StandardOutput/stdoutput-sync.cs"::: +:::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/Process/StandardOutput/stdoutput-sync.fs"::: :::code language="vb" source="~/snippets/visualbasic/api/system.diagnostics/process/standardoutput/stdoutput-sync.vb"::: There is a similar issue when you read all text from both the standard output and standard error streams. The following example performs a read operation on both streams. It avoids the deadlock condition by performing asynchronous read operations on the stream. A deadlock condition results if the parent process calls `p.StandardOutput.ReadToEnd` followed by `p.StandardError.ReadToEnd` and the child process writes enough text to fill its error stream. The parent process would wait indefinitely for the child process to close its stream. The child process would wait indefinitely for the parent to read from the full stream. :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/Process/StandardOutput/stdoutput-async.cs"::: +:::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/Process/StandardOutput/stdoutput-async.fs"::: :::code language="vb" source="~/snippets/visualbasic/api/system.diagnostics/process/standardoutput/stdoutput-async.vb"::: You can use asynchronous read operations to avoid these dependencies and their deadlock potential. Alternately, you can avoid the deadlock condition by creating two threads and reading the output of each stream on a separate thread. @@ -5144,6 +5190,7 @@ There is a similar issue when you read all text from both the standard output an :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Process_StandardOutput/CPP/process_standardoutput.cpp"::: :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/Process/StandardOutput/process_standardoutput.cs"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/Process/StandardOutput/process_standardoutput.fs"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Process_StandardOutput/VB/process_standardoutput.vb"::: ]]> @@ -5259,6 +5306,7 @@ There is a similar issue when you read all text from both the standard output an :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Process.Start_instance/CPP/processstart.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/Process/Overview/processstart.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/Process/Overview/processstart.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Process.Start_instance/VB/processstart.vb" id="Snippet1"::: ]]> @@ -5374,6 +5422,7 @@ The member :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Process.Start_static/CPP/processstartstatic.cpp"::: :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/Process/Overview/processstartstatic.cs"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/Process/Overview/processstartstatic.fs"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Process.Start_static/VB/processstartstatic.vb"::: ]]> @@ -5499,6 +5548,7 @@ The member :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Process.Start_static/CPP/processstartstatic.cpp"::: :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/Process/Overview/processstartstatic.cs"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/Process/Overview/processstartstatic.fs"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Process.Start_static/VB/processstartstatic.vb"::: ]]> @@ -5664,6 +5714,7 @@ The file specified in the could not be found. @@ -5773,6 +5824,7 @@ The file specified in the could not be found. The following code example shows the use of this overload to start an executable file and also demonstrates the throwing of a when an attempt is made to start an application associated with a nonexecutable file. :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/Process/Start/program.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/Process/Start/program.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Diagnostics.Process.Start/VB/program.vb" id="Snippet1"::: ]]> @@ -5958,6 +6010,7 @@ The file specified in the could not be found. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Process.Start_instance/CPP/processstart.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/Process/Overview/processstart.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/Process/Overview/processstart.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Process.Start_instance/VB/processstart.vb" id="Snippet1"::: ]]> @@ -6118,6 +6171,7 @@ The file specified in the could not be found. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Process_SynchronizingObject/CPP/remarks.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/Process/SynchronizingObject/remarks.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/Process/SynchronizingObject/remarks.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Process_SynchronizingObject/VB/remarks.vb" id="Snippet2"::: Typically, this property is set when the component is placed inside a control or form, because those components are bound to a specific thread. @@ -6253,6 +6307,7 @@ The file specified in the could not be found. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Diag_Process_MemoryProperties64/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/Process/BasePriority/source.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/Process/BasePriority/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Diag_Process_MemoryProperties64/VB/source.vb" id="Snippet1"::: ]]> @@ -6327,6 +6382,7 @@ The file specified in the could not be found. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Diag_Process_MemoryProperties64/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/Process/BasePriority/source.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/Process/BasePriority/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Diag_Process_MemoryProperties64/VB/source.vb" id="Snippet1"::: ]]> @@ -6404,6 +6460,7 @@ The file specified in the could not be found. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Diag_Process_MemoryProperties64/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/Process/BasePriority/source.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/Process/BasePriority/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Diag_Process_MemoryProperties64/VB/source.vb" id="Snippet1"::: ]]> @@ -6545,6 +6602,7 @@ The file specified in the could not be found. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Diag_Process_MemoryProperties64/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/Process/BasePriority/source.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/Process/BasePriority/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Diag_Process_MemoryProperties64/VB/source.vb" id="Snippet1"::: ]]> @@ -7099,6 +7157,7 @@ No process is associated with this o :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/process_sample/CPP/process_sample.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/Process/WorkingSet/process_sample.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/Process/WorkingSet/process_sample.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/process_sample/VB/process_sample.vb" id="Snippet1"::: ]]> @@ -7180,6 +7239,7 @@ No process is associated with this o :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Diag_Process_MemoryProperties64/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/Process/BasePriority/source.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Diagnostics/Process/BasePriority/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Diag_Process_MemoryProperties64/VB/source.vb" id="Snippet1"::: ]]> From a8d0cee0a30eaa084808fd25d5e0da8dcb23bbc4 Mon Sep 17 00:00:00 2001 From: Albert Du <52804499+albert-du@users.noreply.github.com> Date: Mon, 24 Jun 2024 07:27:12 -0700 Subject: [PATCH 06/10] F# snippets for Dictionary (#10056) * constructor * remainder * Remove empty snippet reference breaking build This is a weird one, snippet32 is completely empty. It's close curly braces for C# and VB --- .../DictionaryTKey,TValue/.ctor/fs.fsproj | 14 ++ .../DictionaryTKey,TValue/.ctor/source.fs | 29 +++ .../DictionaryTKey,TValue/.ctor/source1.fs | 33 +++ .../DictionaryTKey,TValue/.ctor/source2.fs | 36 ++++ .../DictionaryTKey,TValue/.ctor/source3.fs | 25 +++ .../DictionaryTKey,TValue/.ctor/source4.fs | 38 ++++ .../DictionaryTKey,TValue/Overview/fs.fsproj | 11 + .../DictionaryTKey,TValue/Overview/source.fs | 139 +++++++++++++ .../DictionaryTKey,TValue/Overview/source2.fs | 18 ++ .../fs.fsproj | 10 + .../source.fs | 192 ++++++++++++++++++ .../Dictionary`2.xml | 39 ++++ 12 files changed, 584 insertions(+) create mode 100644 snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/fs.fsproj create mode 100644 snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source.fs create mode 100644 snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source1.fs create mode 100644 snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source2.fs create mode 100644 snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source3.fs create mode 100644 snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source4.fs create mode 100644 snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/fs.fsproj create mode 100644 snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.fs create mode 100644 snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source2.fs create mode 100644 snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/fs.fsproj create mode 100644 snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.fs diff --git a/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/fs.fsproj b/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/fs.fsproj new file mode 100644 index 00000000000..38623d08ff1 --- /dev/null +++ b/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/fs.fsproj @@ -0,0 +1,14 @@ + + + Exe + net8.0 + + + + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source.fs b/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source.fs new file mode 100644 index 00000000000..ea1f9e31aee --- /dev/null +++ b/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source.fs @@ -0,0 +1,29 @@ +module source +// +open System.Collections.Generic + +// Create a new sorted dictionary of strings, with string +// keys. +let openWith = SortedDictionary() + +// Add some elements to the dictionary. +openWith.Add("txt", "notepad.exe") +openWith.Add("bmp", "paint.exe") +openWith.Add("dib", "paint.exe") +openWith.Add("rtf", "wordpad.exe") + +// Create a Dictionary of strings with string keys, and +// initialize it with the contents of the sorted dictionary. +let copy = Dictionary openWith + +// List the contents of the copy. +printfn "" + +for kvp in copy do + printfn $"Key = {kvp.Key}, Value = {kvp.Value}" +// This code example produces the following output: +// Key = bmp, Value = paint.exe +// Key = dib, Value = paint.exe +// Key = rtf, Value = wordpad.exe +// Key = txt, Value = notepad.exe +// diff --git a/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source1.fs b/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source1.fs new file mode 100644 index 00000000000..8da7957c114 --- /dev/null +++ b/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source1.fs @@ -0,0 +1,33 @@ +module source1 +// +open System +open System.Collections.Generic + +// Create a new sorted dictionary of strings, with string +// keys and a case-insensitive comparer. +let openWith = + SortedDictionary StringComparer.CurrentCultureIgnoreCase + +// Add some elements to the dictionary. +openWith.Add("txt", "notepad.exe") +openWith.Add("Bmp", "paint.exe") +openWith.Add("DIB", "paint.exe") +openWith.Add("rtf", "wordpad.exe") + +// Create a Dictionary of strings with string keys and a +// case-insensitive equality comparer, and initialize it +// with the contents of the sorted dictionary. +let copy = + Dictionary(openWith, StringComparer.CurrentCultureIgnoreCase) + +// List the contents of the copy. +printfn "" + +for kvp in copy do + printfn $"Key = {kvp.Key}, Value = {kvp.Value}" +// This code example produces the following output: +// Key = Bmp, Value = paint.exe +// Key = DIB, Value = paint.exe +// Key = rtf, Value = wordpad.exe +// Key = txt, Value = notepad.exe +// diff --git a/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source2.fs b/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source2.fs new file mode 100644 index 00000000000..64297aa5c89 --- /dev/null +++ b/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source2.fs @@ -0,0 +1,36 @@ +module source2 +// +open System +open System.Collections.Generic + +// Create a new Dictionary of strings, with string keys +// and a case-insensitive comparer for the current culture. +let openWith = Dictionary StringComparer.CurrentCultureIgnoreCase + +// Add some elements to the dictionary. +openWith.Add("txt", "notepad.exe") +openWith.Add("bmp", "paint.exe") +openWith.Add("DIB", "paint.exe") +openWith.Add("rtf", "wordpad.exe") + +// Try to add a fifth element with a key that is the same +// except for case; this would be allowed with the default +// comparer. +try + openWith.Add("BMP", "paint.exe") +with :? ArgumentException -> + printfn "\nBMP is already in the dictionary." + +// List the contents of the sorted dictionary. +printfn "" + +for kvp in openWith do + printfn $"Key = {kvp.Key}, Value = {kvp.Value}" +// This code example produces the following output: +// BMP is already in the dictionary. +// +// Key = txt, Value = notepad.exe +// Key = bmp, Value = paint.exe +// Key = DIB, Value = paint.exe +// Key = rtf, Value = wordpad.exe +// diff --git a/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source3.fs b/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source3.fs new file mode 100644 index 00000000000..f9ab89fb9dc --- /dev/null +++ b/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source3.fs @@ -0,0 +1,25 @@ +module source3 +// +open System.Collections.Generic + +// Create a new dictionary of strings, with string keys and +// an initial capacity of 4. +let openWith = Dictionary 4 + +// Add 4 elements to the dictionary. +openWith.Add("txt", "notepad.exe") +openWith.Add("bmp", "paint.exe") +openWith.Add("dib", "paint.exe") +openWith.Add("rtf", "wordpad.exe") + +// List the contents of the dictionary. +printfn "" + +for kvp in openWith do + printfn $"Key = {kvp.Key}, Value = {kvp.Value}" +// This code example produces the following output: +// Key = txt, Value = notepad.exe +// Key = bmp, Value = paint.exe +// Key = dib, Value = paint.exe +// Key = rtf, Value = wordpad.exe +// diff --git a/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source4.fs b/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source4.fs new file mode 100644 index 00000000000..23cf74eb647 --- /dev/null +++ b/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source4.fs @@ -0,0 +1,38 @@ +module source4 +// +open System +open System.Collections.Generic + +// Create a new dictionary of strings, with string keys, an +// initial capacity of 5, and a case-insensitive equality +// comparer. +let openWith = + Dictionary(5, StringComparer.CurrentCultureIgnoreCase) + +// Add 4 elements to the dictionary. +openWith.Add("txt", "notepad.exe") +openWith.Add("bmp", "paint.exe") +openWith.Add("DIB", "paint.exe") +openWith.Add("rtf", "wordpad.exe") + +// Try to add a fifth element with a key that is the same +// except for case; this would be allowed with the default +// comparer. +try + openWith.Add("BMP", "paint.exe") +with :? ArgumentException -> + printfn "\nBMP is already in the dictionary." + +// List the contents of the dictionary. +printfn "" + +for kvp in openWith do + printfn $"Key = {kvp.Key}, Value = {kvp.Value}" +// This code example produces the following output: +// BMP is already in the dictionary. +// +// Key = txt, Value = notepad.exe +// Key = bmp, Value = paint.exe +// Key = DIB, Value = paint.exe +// Key = rtf, Value = wordpad.exe +// diff --git a/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/fs.fsproj b/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/fs.fsproj new file mode 100644 index 00000000000..086755acf55 --- /dev/null +++ b/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/fs.fsproj @@ -0,0 +1,11 @@ + + + Exe + net8.0 + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.fs b/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.fs new file mode 100644 index 00000000000..9e5ddf98bf6 --- /dev/null +++ b/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.fs @@ -0,0 +1,139 @@ +module source + +open System +open System.Collections.Generic + +// +// +// Create a new dictionary of strings, with string keys. +let openWith = Dictionary() + +// Add some elements to the dictionary. There are no +// duplicate keys, but some of the values are duplicates. +openWith.Add("txt", "notepad.exe") +openWith.Add("bmp", "paint.exe") +openWith.Add("dib", "paint.exe") +openWith.Add("rtf", "wordpad.exe") + +// The Add method throws an exception if the new key is +// already in the dictionary. +try + openWith.Add("txt", "winword.exe") +with :? ArgumentException -> + printfn "An element with Key = \"txt\" already exists." +// + +// +// The Item property is another name for the indexer, so you +// can omit its name when accessing elements. +printfn $"""For key = "rtf", value = {openWith["rtf"]}""" + +// The indexer can be used to change the value associated +// with a key. +openWith["rtf"] <- "winword.exe" +printfn $"""For key = "rtf", value = {openWith["rtf"]}""" + +// If a key does not exist, setting the indexer for that key +// adds a new key/value pair. +openWith["doc"] <- "winword.exe" +// + +// +// The indexer throws an exception if the requested key is +// not in the dictionary. +try + printfn $"""For key = "tif", value = {openWith["tif"]}""" +with :? KeyNotFoundException -> + printfn "Key = \"tif\" is not found." +// + +// +// When a program often has to try keys that turn out not to +// be in the dictionary, TryGetValue can be a more efficient +// way to retrieve values. +match openWith.TryGetValue "tif" with +| true, value -> printfn $"For key = \"tif\", value = {value}." +| _ -> printfn "Key = \"tif\" is not found." +// + +// +// ContainsKey can be used to test keys before inserting +// them. +if openWith.ContainsKey "ht" |> not then + openWith.Add("ht", "hypertrm.exe") + printfn $"""Value added for key = "ht": {openWith["ht"]}""" +// + +// +// When you use foreach to enumerate dictionary elements, +// the elements are retrieved as KeyValuePair objects. +printfn "" + +for kvp in openWith do + printfn $"Key = {kvp.Key}, Value = {kvp.Value}" +// + +// +// To get the values alone, use the Values property. +let valueColl = openWith.Values + +// The elements of the ValueCollection are strongly typed +// with the type that was specified for dictionary values. +printfn "" + +for s in valueColl do + printfn $"Value = {s}" +// + +// +// To get the keys alone, use the Keys property. +let keyColl = openWith.Keys + +// The elements of the KeyCollection are strongly typed +// with the type that was specified for dictionary keys. +printfn "" + +for s in keyColl do + printfn $"Key = {s}" +// + +// +// Use the Remove method to remove a key/value pair. +printfn "\nRemove(\"doc\")" +openWith.Remove "doc" |> ignore + +if openWith.ContainsKey "doc" |> not then + printfn "Key \"doc\" is not found." +// +// This code example produces the following output: +// An element with Key = "txt" already exists. +// For key = "rtf", value = wordpad.exe. +// For key = "rtf", value = winword.exe. +// Key = "tif" is not found. +// Key = "tif" is not found. +// Value added for key = "ht": hypertrm.exe +// +// Key = txt, Value = notepad.exe +// Key = bmp, Value = paint.exe +// Key = dib, Value = paint.exe +// Key = rtf, Value = winword.exe +// Key = doc, Value = winword.exe +// Key = ht, Value = hypertrm.exe +// +// Value = notepad.exe +// Value = paint.exe +// Value = paint.exe +// Value = winword.exe +// Value = winword.exe +// Value = hypertrm.exe +// +// Key = txt +// Key = bmp +// Key = dib +// Key = rtf +// Key = doc +// Key = ht +// +// Remove("doc") +// Key "doc" is not found. +// diff --git a/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source2.fs b/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source2.fs new file mode 100644 index 00000000000..cfed75ef885 --- /dev/null +++ b/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source2.fs @@ -0,0 +1,18 @@ +module source2 + +open System.Collections.Generic + +// Create a new dictionary of strings, with string keys. +let myDictionary = Dictionary() + +// Add some elements to the dictionary. There are no +// duplicate keys, but some of the values are duplicates. +myDictionary.Add("txt", "notepad.exe") +myDictionary.Add("bmp", "paint.exe") +myDictionary.Add("dib", "paint.exe") +myDictionary.Add("rtf", "wordpad.exe") + +// +for kvp in myDictionary do + printfn $"Key = {kvp.Key}, Value = {kvp.Value}" +// diff --git a/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/fs.fsproj b/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/fs.fsproj new file mode 100644 index 00000000000..02825a27616 --- /dev/null +++ b/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.fs b/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.fs new file mode 100644 index 00000000000..ac6b69ab830 --- /dev/null +++ b/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.fs @@ -0,0 +1,192 @@ +// Do not use snippets 31 & 32 with snippet 21; snippet 21 goes +// with snippet 2, which already provides enough context. (2 and +// 21 were originally one snippet, but had to be split when 31 +// was added, because I don't trust overlapping snippets any +// more.) +// +// Note further that {2, 21} is NOT USED right now because +// the complete sample (snippet 1) is located in IDictionary.Add. +// +// The groups are: +// {2, 21} - Add +// {31, 3, 4, 32} - Item +// {31, 6, 32} - Contains +// {31, 7, 32} - GetEnumerator +// {31, 8, 7, 32} - Values +// {31, 9, 7, 32} - Keys +// {31, 10, 32} - Remove +// -> PLS MAKE SURE THESE STAY IN SYNC WITH DESCRIPTION.TXT <- +// +// +// +open System +open System.Collections +open System.Collections.Generic + +// +// Create a new dictionary of strings, with string keys, +// and access it using the IDictionary interface. +let openWith: IDictionary = Dictionary() + +// Add some elements to the dictionary. There are no +// duplicate keys, but some of the values are duplicates. +// IDictionary.Add throws an exception if incorrect types +// are supplied for key or value. +openWith.Add("txt", "notepad.exe") +openWith.Add("bmp", "paint.exe") +openWith.Add("dib", "paint.exe") +openWith.Add("rtf", "wordpad.exe") +// +// +// +type Example() = class end + +try + openWith.Add(42, Example()) +with :? ArgumentException as ex -> + printfn $"An exception was caught for IDictionary.Add. Exception message:\n\t{ex.Message}\n" + +// The Add method throws an exception if the new key is +// already in the dictionary. +try + openWith.Add("txt", "winword.exe") +with :? ArgumentException -> + printfn "An element with Key = \"txt\" already exists." +// + +// +// The Item property is another name for the indexer, so you +// can omit its name when accessing elements. +printfn $"""For key = "rtf", value = {openWith.["rtf"]}.""" + +// The indexer can be used to change the value associated +// with a key. +openWith["rtf"] <- "winword.exe" +printfn $"""For key = "rtf", value = {openWith.["rtf"]}.""" + +// If a key does not exist, setting the indexer for that key +// adds a new key/value pair. +openWith["doc"] <- "winword.exe" + +// The indexer returns null if the key is of the wrong data +// type. +printfn "The indexer returns null if the key is of the wrong type:" +printfn $"""For key = 2, value = {openWith.[2]}.""" + +// The indexer throws an exception when setting a value +// if the key is of the wrong data type. +try + openWith[2] <- "This does not get added." +with :? ArgumentException -> + printfn "A key of the wrong type was specified when assigning to the indexer." +// + +// +// Unlike the default Item property on the Dictionary class +// itself, IDictionary.Item does not throw an exception +// if the requested key is not in the dictionary. +printfn $"""For key = "tif", value = {openWith.["tif"]}.""" +// + +// +// Contains can be used to test keys before inserting +// them. +if openWith.Contains "ht" |> not then + openWith.Add("ht", "hypertrm.exe") + printfn $"""Value added for key = "ht": {openWith["ht"]}""" + +// IDictionary.Contains returns false if the wrong data +// type is supplied. +printfn $"openWith.Contains(29.7) returns {openWith.Contains 29.7}" +// + +// +// When you use foreach to enumerate dictionary elements +// with the IDictionary interface, the elements are retrieved +// as DictionaryEntry objects instead of KeyValuePair objects. +printfn "" + +for de in openWith do + let de = de :?> DictionaryEntry + printfn $"For key = {de.Key}, value = {de.Value}" +// + +// +// To get the values alone, use the Values property. +let icoll: ICollection = openWith.Values + +// The elements of the collection are strongly typed +// with the type that was specified for dictionary values, +// even though the ICollection interface is not strongly +// typed. +printfn "" + +for s in icoll do + printfn $"Value = {s}" +// + +// +// To get the keys alone, use the Keys property. +let icoll2: ICollection = openWith.Keys + +// The elements of the collection are strongly typed +// with the type that was specified for dictionary keys, +// even though the ICollection interface is not strongly +// typed. +printfn "" + +for s in icoll2 do + printfn $"Key = {s}" +// + +// +// Use the Remove method to remove a key/value pair. No +// exception is thrown if the wrong data type is supplied. +printfn "\nRemove(\"dib\")" +openWith.Remove "dib" + +if openWith.Contains "dib" |> not then + printfn "Key \"dib\" is not found." +// +// +// + +// This code example produces the following output: +// An exception was caught for IDictionary.Add. Exception message: +// The value "42" is not of type "System.String" and cannot be used in this generic collection. +// Parameter name: key +// +// An element with Key = "txt" already exists. +// For key = "rtf", value = wordpad.exe. +// For key = "rtf", value = winword.exe. +// The indexer returns null if the key is of the wrong type: +// For key = 2, value = . +// A key of the wrong type was specified when assigning to the indexer. +// For key = "tif", value = . +// Value added for key = "ht": hypertrm.exe +// openWith.Contains(29.7) returns False +// +// Key = txt, Value = notepad.exe +// Key = bmp, Value = paint.exe +// Key = dib, Value = paint.exe +// Key = rtf, Value = winword.exe +// Key = doc, Value = winword.exe +// Key = ht, Value = hypertrm.exe +// +// Value = notepad.exe +// Value = paint.exe +// Value = paint.exe +// Value = winword.exe +// Value = winword.exe +// Value = hypertrm.exe +// +// Key = txt +// Key = bmp +// Key = dib +// Key = rtf +// Key = doc +// Key = ht +// +// Remove("dib") +// Key "dib" is not found. +// diff --git a/xml/System.Collections.Generic/Dictionary`2.xml b/xml/System.Collections.Generic/Dictionary`2.xml index 681ac00d3c5..dba903564ad 100644 --- a/xml/System.Collections.Generic/Dictionary`2.xml +++ b/xml/System.Collections.Generic/Dictionary`2.xml @@ -156,6 +156,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Generic.Dictionary/cpp/source2.cpp" id="Snippet11"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source2.cs" id="Snippet11"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source2.fs" id="Snippet11"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary/VB/source2.vb" id="Snippet11"::: The `foreach` statement is a wrapper around the enumerator, which allows only reading from the collection, not writing to it. @@ -179,6 +180,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Generic.Dictionary/cpp/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary/VB/source.vb" id="Snippet1"::: ]]> @@ -262,6 +264,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Generic.Dictionary/cpp/source.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.cs" interactive="try-dotnet-method" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary/VB/source.vb" id="Snippet2"::: ]]> @@ -327,6 +330,7 @@ The following code example shows how to use the constructor to initialize a with sorted content from another dictionary. The code example creates a and populates it with data in random order, then passes the to the constructor, creating a that is sorted. This is useful if you need to build a sorted dictionary that at some point becomes static; copying the data from a to a improves retrieval speed. :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary.ctor_IDic/VB/source.vb" id="Snippet1"::: ]]> @@ -453,6 +457,7 @@ The following code example creates a with a case-insensitive equality comparer for the current culture. The example adds four elements, some with lower-case keys and some with upper-case keys. The example then attempts to add an element with a key that differs from an existing key only by case, catches the resulting exception, and displays an error message. Finally, the example displays the elements in the dictionary. :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source2.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source2.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary.ctor_IEqC/VB/source.vb" id="Snippet1"::: ]]> @@ -520,6 +525,7 @@ The following code example creates a dictionary with an initial capacity of 4 and populates it with 4 entries. :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source3.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source3.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary.ctor_Int32/VB/source.vb" id="Snippet1"::: ]]> @@ -604,6 +610,7 @@ > When you create a new dictionary with a case-insensitive comparer and populate it with entries from a dictionary that uses a case-sensitive comparer, as in this example, an exception occurs if the input dictionary has keys that differ only by case. :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary.ctor_IDicIEqC/VB/source.vb" id="Snippet1"::: ]]> @@ -744,6 +751,7 @@ The following code example creates a with an initial capacity of 5 and a case-insensitive equality comparer for the current culture. The example adds four elements, some with lower-case keys and some with upper-case keys. The example then attempts to add an element with a key that differs from an existing key only by case, catches the resulting exception, and displays an error message. Finally, the example displays the elements in the dictionary. :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source4.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source4.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary.ctor_Int32IEqC/VB/source.vb" id="Snippet1"::: ]]> @@ -882,6 +890,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Generic.Dictionary/cpp/source.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary/VB/source.vb" id="Snippet2"::: ]]> @@ -1089,12 +1098,15 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Generic.Dictionary/cpp/source.cpp" id="Snippet6"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.cs" id="Snippet6"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.fs" id="Snippet6"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary/VB/source.vb" id="Snippet6"::: :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Generic.Dictionary/cpp/source.cpp" id="Snippet5"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.cs" id="Snippet5"::: +:::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.fs" id="Snippet5"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary/VB/source.vb" id="Snippet5"::: :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Generic.Dictionary/cpp/source.cpp" id="Snippet4"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.cs" id="Snippet4"::: +:::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary/VB/source.vb" id="Snippet4"::: ]]> @@ -1474,15 +1486,19 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Generic.Dictionary/cpp/source.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.cs" interactive="try-dotnet-method" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary/VB/source.vb" id="Snippet2"::: :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Generic.Dictionary/cpp/source.cpp" id="Snippet3"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.cs" id="Snippet3"::: +:::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary/VB/source.vb" id="Snippet3"::: :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Generic.Dictionary/cpp/source.cpp" id="Snippet4"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.cs" id="Snippet4"::: +:::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary/VB/source.vb" id="Snippet4"::: :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Generic.Dictionary/cpp/source.cpp" id="Snippet5"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.cs" id="Snippet5"::: +:::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.fs" id="Snippet5"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary/VB/source.vb" id="Snippet5"::: ]]> @@ -1550,9 +1566,11 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Generic.Dictionary/cpp/source.cpp" id="Snippet9"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.cs" id="Snippet9"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.fs" id="Snippet9"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary/VB/source.vb" id="Snippet9"::: :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Generic.Dictionary/cpp/source.cpp" id="Snippet7"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.cs" id="Snippet7"::: +:::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.fs" id="Snippet7"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary/VB/source.vb" id="Snippet7"::: ]]> @@ -1688,6 +1706,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Generic.Dictionary/cpp/source.cpp" id="Snippet10"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.cs" id="Snippet10"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.fs" id="Snippet10"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary/VB/source.vb" id="Snippet10"::: ]]> @@ -2497,6 +2516,7 @@ finally { The code example demonstrates the use of several other members of the interface. :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary.IDictionary/VB/source.vb" id="Snippet1"::: ]]> @@ -2578,8 +2598,10 @@ finally { The code example is part of a larger example, including output, provided for the method. :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.cs" id="Snippet31"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.fs" id="Snippet31"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary.IDictionary/VB/source.vb" id="Snippet31"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.cs" id="Snippet6"::: +:::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.fs" id="Snippet6"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary.IDictionary/VB/source.vb" id="Snippet6"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.cs" id="Snippet32"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary.IDictionary/VB/source.vb" id="Snippet32"::: @@ -2666,8 +2688,10 @@ finally { The code example is part of a larger example, including output, provided for the method. :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.cs" id="Snippet31"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.fs" id="Snippet31"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary.IDictionary/VB/source.vb" id="Snippet31"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.cs" id="Snippet7"::: +:::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.fs" id="Snippet7"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary.IDictionary/VB/source.vb" id="Snippet7"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.cs" id="Snippet32"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary.IDictionary/VB/source.vb" id="Snippet32"::: @@ -2864,10 +2888,13 @@ finally { The code example is part of a larger example, including output, provided for the method. :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.cs" id="Snippet31"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.fs" id="Snippet31"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary.IDictionary/VB/source.vb" id="Snippet31"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.cs" id="Snippet3"::: +:::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary.IDictionary/VB/source.vb" id="Snippet3"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.cs" id="Snippet4"::: +:::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary.IDictionary/VB/source.vb" id="Snippet4"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.cs" id="Snippet32"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary.IDictionary/VB/source.vb" id="Snippet32"::: @@ -2941,10 +2968,13 @@ finally { The code example is part of a larger example, including output, provided for the method. :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.cs" id="Snippet31"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.fs" id="Snippet31"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary.IDictionary/VB/source.vb" id="Snippet31"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.cs" id="Snippet9"::: +:::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.fs" id="Snippet9"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary.IDictionary/VB/source.vb" id="Snippet9"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.cs" id="Snippet7"::: +:::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.fs" id="Snippet7"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary.IDictionary/VB/source.vb" id="Snippet7"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.cs" id="Snippet32"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary.IDictionary/VB/source.vb" id="Snippet32"::: @@ -3012,8 +3042,10 @@ finally { The code example is part of a larger example, including output, provided for the method. :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.cs" id="Snippet31"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.fs" id="Snippet31"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary.IDictionary/VB/source.vb" id="Snippet31"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.cs" id="Snippet10"::: +:::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.fs" id="Snippet10"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary.IDictionary/VB/source.vb" id="Snippet10"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.cs" id="Snippet32"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary.IDictionary/VB/source.vb" id="Snippet32"::: @@ -3081,10 +3113,13 @@ finally { The code example is part of a larger example, including output, provided for the method. :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.cs" id="Snippet31"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.fs" id="Snippet31"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary.IDictionary/VB/source.vb" id="Snippet31"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.cs" id="Snippet8"::: +:::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.fs" id="Snippet8"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary.IDictionary/VB/source.vb" id="Snippet8"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.cs" id="Snippet7"::: +:::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.fs" id="Snippet7"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary.IDictionary/VB/source.vb" id="Snippet7"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/System.Collections.IDictionary.Add/source.cs" id="Snippet32"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary.IDictionary/VB/source.vb" id="Snippet32"::: @@ -3379,9 +3414,11 @@ Unlike the method, this :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Generic.Dictionary/cpp/source.cpp" id="Snippet5"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.cs" id="Snippet5"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.fs" id="Snippet5"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary/VB/source.vb" id="Snippet5"::: :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Generic.Dictionary/cpp/source.cpp" id="Snippet4"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.cs" id="Snippet4"::: +:::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary/VB/source.vb" id="Snippet4"::: ]]> @@ -3449,9 +3486,11 @@ Unlike the method, this :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Generic.Dictionary/cpp/source.cpp" id="Snippet8"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.cs" id="Snippet8"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.fs" id="Snippet8"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary/VB/source.vb" id="Snippet8"::: :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Generic.Dictionary/cpp/source.cpp" id="Snippet7"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.cs" id="Snippet7"::: +:::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/Overview/source.fs" id="Snippet7"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary/VB/source.vb" id="Snippet7"::: ]]> From 0d937b8ba32862cb1daa717463c4def03ae816be Mon Sep 17 00:00:00 2001 From: Albert Du <52804499+albert-du@users.noreply.github.com> Date: Mon, 24 Jun 2024 07:28:37 -0700 Subject: [PATCH 07/10] F# snippets for HashSet (#10055) --- .../HashSetT/.ctor/Program.fs | 41 ++++++++ .../HashSetT/.ctor/fs.fsproj | 11 +++ .../HashSetT/.ctor/source2.fs | 97 +++++++++++++++++++ .../HashSetT/Clear/Program.fs | 29 ++++++ .../HashSetT/Clear/fs.fsproj | 10 ++ .../HashSetT/Contains/Program.fs | 40 ++++++++ .../HashSetT/Contains/fs.fsproj | 10 ++ .../HashSetT/IsProperSubsetOf/Program.fs | 67 +++++++++++++ .../HashSetT/IsProperSubsetOf/fs.fsproj | 10 ++ .../HashSetT/Overview/Program.fs | 45 +++++++++ .../HashSetT/Overview/fs.fsproj | 10 ++ .../HashSetT/SymmetricExceptWith/Program.fs | 39 ++++++++ .../HashSetT/SymmetricExceptWith/fs.fsproj | 10 ++ xml/System.Collections.Generic/HashSet`1.xml | 20 ++++ 14 files changed, 439 insertions(+) create mode 100644 snippets/fsharp/System.Collections.Generic/HashSetT/.ctor/Program.fs create mode 100644 snippets/fsharp/System.Collections.Generic/HashSetT/.ctor/fs.fsproj create mode 100644 snippets/fsharp/System.Collections.Generic/HashSetT/.ctor/source2.fs create mode 100644 snippets/fsharp/System.Collections.Generic/HashSetT/Clear/Program.fs create mode 100644 snippets/fsharp/System.Collections.Generic/HashSetT/Clear/fs.fsproj create mode 100644 snippets/fsharp/System.Collections.Generic/HashSetT/Contains/Program.fs create mode 100644 snippets/fsharp/System.Collections.Generic/HashSetT/Contains/fs.fsproj create mode 100644 snippets/fsharp/System.Collections.Generic/HashSetT/IsProperSubsetOf/Program.fs create mode 100644 snippets/fsharp/System.Collections.Generic/HashSetT/IsProperSubsetOf/fs.fsproj create mode 100644 snippets/fsharp/System.Collections.Generic/HashSetT/Overview/Program.fs create mode 100644 snippets/fsharp/System.Collections.Generic/HashSetT/Overview/fs.fsproj create mode 100644 snippets/fsharp/System.Collections.Generic/HashSetT/SymmetricExceptWith/Program.fs create mode 100644 snippets/fsharp/System.Collections.Generic/HashSetT/SymmetricExceptWith/fs.fsproj diff --git a/snippets/fsharp/System.Collections.Generic/HashSetT/.ctor/Program.fs b/snippets/fsharp/System.Collections.Generic/HashSetT/.ctor/Program.fs new file mode 100644 index 00000000000..6c9d419b933 --- /dev/null +++ b/snippets/fsharp/System.Collections.Generic/HashSetT/.ctor/Program.fs @@ -0,0 +1,41 @@ +module Program + +// +open System.Collections.Generic + +// +let displaySet (set: HashSet) = + printf "{" + + for i in set do + printf $" {i}" + + printfn " }" + +let lowNumbers = HashSet() +let highNumbers = HashSet() + +for i = 0 to 5 do + lowNumbers.Add i |> ignore + +for i = 3 to 9 do + highNumbers.Add i |> ignore + +printf $"lowNumbers contains {lowNumbers.Count} elements: " +displaySet lowNumbers + +printf $"highNumbers contains {highNumbers.Count} elements: " +displaySet highNumbers + +printfn "highNumbers ExceptWith lowNumbers..." +highNumbers.ExceptWith(lowNumbers) + +printf $"highNumbers contains {highNumbers.Count} elements: " +displaySet highNumbers +// This example provides output similar to the following: +// lowNumbers contains 6 elements: { 0 1 2 3 4 5 } +// highNumbers contains 7 elements: { 3 4 5 6 7 8 9 } +// highNumbers ExceptWith lowNumbers... +// highNumbers contains 4 elements: { 6 7 8 9 } +// +// diff --git a/snippets/fsharp/System.Collections.Generic/HashSetT/.ctor/fs.fsproj b/snippets/fsharp/System.Collections.Generic/HashSetT/.ctor/fs.fsproj new file mode 100644 index 00000000000..543f81fd600 --- /dev/null +++ b/snippets/fsharp/System.Collections.Generic/HashSetT/.ctor/fs.fsproj @@ -0,0 +1,11 @@ + + + Exe + net8.0 + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Collections.Generic/HashSetT/.ctor/source2.fs b/snippets/fsharp/System.Collections.Generic/HashSetT/.ctor/source2.fs new file mode 100644 index 00000000000..9bd73eaa849 --- /dev/null +++ b/snippets/fsharp/System.Collections.Generic/HashSetT/.ctor/source2.fs @@ -0,0 +1,97 @@ +module source2 + +open System +open System.Collections.Generic + +// +let allVehicles = HashSet StringComparer.OrdinalIgnoreCase +let someVehicles = ResizeArray() + +someVehicles.Add "Planes" +someVehicles.Add "Trains" +someVehicles.Add "Automobiles" + +// Add in the vehicles contained in the someVehicles list. +allVehicles.UnionWith someVehicles + +printfn "The current HashSet contains:\n" + +for vehicle in allVehicles do + printfn $"{vehicle}" + +allVehicles.Add "Ships" |> ignore +allVehicles.Add "Motorcycles" |> ignore +allVehicles.Add "Rockets" |> ignore +allVehicles.Add "Helicopters" |> ignore +allVehicles.Add "Submarines" |> ignore + +printfn "\nThe updated HashSet contains:\n" + +for vehicle in allVehicles do + printfn $"{vehicle}" + +// Verify that the 'All Vehicles' set contains at least the vehicles in +// the 'Some Vehicles' list. +if allVehicles.IsSupersetOf someVehicles then + printfn "\nThe 'All' vehicles set contains everything in 'Some' vehicles list." + +// Check for Rockets. Here the OrdinalIgnoreCase comparer will compare +// true for the mixed-case vehicle type. +if allVehicles.Contains "roCKeTs" then + printfn "\nThe 'All' vehicles set contains 'roCKeTs'" + +allVehicles.ExceptWith someVehicles +printfn "\nThe excepted HashSet contains:\n" + +for vehicle in allVehicles do + printfn $"{vehicle}" + +// Predicate to determine vehicle 'coolness'. +let isNotSuperCool vehicle = + let superCool = vehicle = "Helicopters" || vehicle = "Motorcycles" + not superCool + +// Remove all the vehicles that are not 'super cool'. +allVehicles.RemoveWhere isNotSuperCool |> ignore + +printfn "\nThe super cool vehicles are:\n" + +for vehicle in allVehicles do + printfn $"{vehicle}" + +// The program writes the following output to the console. +// +// The current HashSet contains: +// +// Planes +// Trains +// Automobiles +// +// The updated HashSet contains: +// +// Planes +// Trains +// Automobiles +// Ships +// Motorcycles +// Rockets +// Helicopters +// Submarines +// +// The 'All' vehicles set contains everything in 'Some' vehicles list. +// +// The 'All' vehicles set contains 'roCKeTs' +// +// The excepted HashSet contains: +// +// Ships +// Motorcycles +// Rockets +// Helicopters +// Submarines +// +// The super cool vehicles are: +// +// Motorcycles +// Helicopters +// diff --git a/snippets/fsharp/System.Collections.Generic/HashSetT/Clear/Program.fs b/snippets/fsharp/System.Collections.Generic/HashSetT/Clear/Program.fs new file mode 100644 index 00000000000..b95c3a0d6ff --- /dev/null +++ b/snippets/fsharp/System.Collections.Generic/HashSetT/Clear/Program.fs @@ -0,0 +1,29 @@ +open System.Collections.Generic + +// +let displaySet (set: HashSet) = + printf "{" + + for i in set do + printf $" {i}" + + printfn " }" +// This example produces output similar to the following: +// Numbers contains 10 elements: { 0 1 2 3 4 5 6 7 8 9 } +// Numbers contains 0 elements: { } +// +let numbers = HashSet() + +for i = 0 to 9 do + numbers.Add i |> ignore + +printf $"Numbers contains {numbers.Count} elements: " +displaySet numbers + +numbers.Clear() +numbers.TrimExcess() + +printf $"Numbers contains {numbers.Count} elements: " +displaySet numbers +// +// diff --git a/snippets/fsharp/System.Collections.Generic/HashSetT/Clear/fs.fsproj b/snippets/fsharp/System.Collections.Generic/HashSetT/Clear/fs.fsproj new file mode 100644 index 00000000000..99d4f2bb01e --- /dev/null +++ b/snippets/fsharp/System.Collections.Generic/HashSetT/Clear/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Collections.Generic/HashSetT/Contains/Program.fs b/snippets/fsharp/System.Collections.Generic/HashSetT/Contains/Program.fs new file mode 100644 index 00000000000..069217599e4 --- /dev/null +++ b/snippets/fsharp/System.Collections.Generic/HashSetT/Contains/Program.fs @@ -0,0 +1,40 @@ +// +open System.Collections.Generic + +// +let isOdd i = i % 2 = 1 + +let displaySet (set: HashSet) = + printf "{" + + for i in set do + printf $" {i}" + + printfn " }" + +let numbers = HashSet() + +for i in 1..20 do + numbers.Add i |> ignore + +// Display all the numbers in the hash table. +printf $"numbers contains {numbers.Count} elements: " +displaySet numbers + +// Remove all odd numbers. +numbers.RemoveWhere isOdd |> ignore +printf $"numbers contains {numbers.Count} elements: " +displaySet numbers + +// Check if the hash table contains 0 and, if so, remove it. +if numbers.Contains 0 then + numbers.Remove 0 |> ignore + +printf $"numbers contains {numbers.Count} elements: " +displaySet numbers +// This example displays the following output: +// numbers contains 20 elements: { 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 } +// numbers contains 10 elements: { 0 2 4 6 8 10 12 14 16 18 } +// numbers contains 9 elements: { 2 4 6 8 10 12 14 16 18 } +// +// diff --git a/snippets/fsharp/System.Collections.Generic/HashSetT/Contains/fs.fsproj b/snippets/fsharp/System.Collections.Generic/HashSetT/Contains/fs.fsproj new file mode 100644 index 00000000000..99d4f2bb01e --- /dev/null +++ b/snippets/fsharp/System.Collections.Generic/HashSetT/Contains/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Collections.Generic/HashSetT/IsProperSubsetOf/Program.fs b/snippets/fsharp/System.Collections.Generic/HashSetT/IsProperSubsetOf/Program.fs new file mode 100644 index 00000000000..3e1d6f00ef9 --- /dev/null +++ b/snippets/fsharp/System.Collections.Generic/HashSetT/IsProperSubsetOf/Program.fs @@ -0,0 +1,67 @@ +// +open System.Collections.Generic + +// +let displaySet (set: HashSet) = + printf "{" + + for i in set do + printf $" {i}" + + printfn " }" + +let lowNumbers = HashSet() +let allNumbers = HashSet() + +for i = 1 to 4 do + lowNumbers.Add i |> ignore + + +for i = 0 to 9 do + allNumbers.Add i |> ignore + +printf $"lowNumbers contains {lowNumbers.Count} elements: " +displaySet lowNumbers + +printf $"allNumbers contains {allNumbers.Count} elements: " +displaySet allNumbers + +printfn $"lowNumbers overlaps allNumbers: {lowNumbers.Overlaps allNumbers}" + +printfn $"allNumbers and lowNumbers are equal sets: {allNumbers.SetEquals lowNumbers}" + +// Show the results of sub/superset testing +printfn $"lowNumbers is a subset of allNumbers: {lowNumbers.IsSubsetOf allNumbers}" +printfn $"allNumbers is a superset of lowNumbers: {allNumbers.IsSupersetOf lowNumbers}" +printfn $"lowNumbers is a proper subset of allNumbers: {lowNumbers.IsProperSubsetOf allNumbers}" +printfn $"allNumbers is a proper superset of lowNumbers: {allNumbers.IsProperSupersetOf lowNumbers}" + +// Modify allNumbers to remove numbers that are not in lowNumbers. +allNumbers.IntersectWith lowNumbers +printf $"allNumbers contains {allNumbers.Count} elements: " +displaySet allNumbers + +printfn $"allNumbers and lowNumbers are equal sets: {allNumbers.SetEquals lowNumbers}" + +// Show the results of sub/superset testing with the modified set. +printfn $"lowNumbers is a subset of allNumbers: {lowNumbers.IsSubsetOf allNumbers}" +printfn $"allNumbers is a superset of lowNumbers: {allNumbers.IsSupersetOf lowNumbers}" +printfn $"lowNumbers is a proper subset of allNumbers: {lowNumbers.IsProperSubsetOf allNumbers}" +printfn $"allNumbers is a proper superset of lowNumbers: {allNumbers.IsProperSupersetOf lowNumbers}" +// This code example produces output similar to the following: +// lowNumbers contains 4 elements: { 1 2 3 4 } +// allNumbers contains 10 elements: { 0 1 2 3 4 5 6 7 8 9 } +// lowNumbers overlaps allNumbers: True +// allNumbers and lowNumbers are equal sets: False +// lowNumbers is a subset of allNumbers: True +// allNumbers is a superset of lowNumbers: True +// lowNumbers is a proper subset of allNumbers: True +// allNumbers is a proper superset of lowNumbers: True +// allNumbers contains 4 elements: { 1 2 3 4 } +// allNumbers and lowNumbers are equal sets: True +// lowNumbers is a subset of allNumbers: True +// allNumbers is a superset of lowNumbers: True +// lowNumbers is a proper subset of allNumbers: False +// allNumbers is a proper superset of lowNumbers: False +// +// diff --git a/snippets/fsharp/System.Collections.Generic/HashSetT/IsProperSubsetOf/fs.fsproj b/snippets/fsharp/System.Collections.Generic/HashSetT/IsProperSubsetOf/fs.fsproj new file mode 100644 index 00000000000..99d4f2bb01e --- /dev/null +++ b/snippets/fsharp/System.Collections.Generic/HashSetT/IsProperSubsetOf/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Collections.Generic/HashSetT/Overview/Program.fs b/snippets/fsharp/System.Collections.Generic/HashSetT/Overview/Program.fs new file mode 100644 index 00000000000..7dd04eef93c --- /dev/null +++ b/snippets/fsharp/System.Collections.Generic/HashSetT/Overview/Program.fs @@ -0,0 +1,45 @@ +open System.Collections.Generic + +// + +let displaySet (collection: HashSet) = + printf "{" + + for i in collection do + printf $" {i}" + + printfn " }" + +// +// +let evenNumbers = HashSet() +let oddNumbers = HashSet() + +for i = 0 to 4 do + // Populate numbers with just even numbers. + evenNumbers.Add(i * 2) |> ignore + + // Populate oddNumbers with just odd numbers. + oddNumbers.Add(i * 2 + 1) |> ignore +// + +printf $"evenNumbers contains {evenNumbers.Count} elements: " +displaySet evenNumbers + +printf $"oddNumbers contains {oddNumbers.Count} elements: " +displaySet oddNumbers + +// Create a new HashSet populated with even numbers. +let numbers = HashSet evenNumbers +printfn "numbers UnionWith oddNumbers..." +numbers.UnionWith oddNumbers + +printf $"numbers contains {numbers.Count} elements: " +displaySet numbers +// +// This example produces output similar to the following: +// evenNumbers contains 5 elements: { 0 2 4 6 8 } +// oddNumbers contains 5 elements: { 1 3 5 7 9 } +// numbers UnionWith oddNumbers... +// numbers contains 10 elements: { 0 2 4 6 8 1 3 5 7 9 } +// diff --git a/snippets/fsharp/System.Collections.Generic/HashSetT/Overview/fs.fsproj b/snippets/fsharp/System.Collections.Generic/HashSetT/Overview/fs.fsproj new file mode 100644 index 00000000000..99d4f2bb01e --- /dev/null +++ b/snippets/fsharp/System.Collections.Generic/HashSetT/Overview/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Collections.Generic/HashSetT/SymmetricExceptWith/Program.fs b/snippets/fsharp/System.Collections.Generic/HashSetT/SymmetricExceptWith/Program.fs new file mode 100644 index 00000000000..a5dfb53bace --- /dev/null +++ b/snippets/fsharp/System.Collections.Generic/HashSetT/SymmetricExceptWith/Program.fs @@ -0,0 +1,39 @@ +// +open System.Collections.Generic + +// +let displaySet (set: HashSet) = + printf "{" + + for i in set do + printf $" {i}" + + printfn " }" + +let lowNumbers = HashSet() +let highNumbers = HashSet() + +for i in 0..5 do + lowNumbers.Add i |> ignore + +for i in 3..9 do + highNumbers.Add i |> ignore + +printf $"lowNumbers contains {lowNumbers.Count} elements: " +displaySet lowNumbers + +printf $"highNumbers contains {highNumbers.Count} elements: " +displaySet highNumbers + +printfn "lowNumbers SymmetricExceptWith highNumbers..." +lowNumbers.SymmetricExceptWith highNumbers + +printf $"lowNumbers contains {lowNumbers.Count} elements: " +displaySet lowNumbers +// This example provides output similar to the following: +// lowNumbers contains 6 elements: { 0 1 2 3 4 5 } +// highNumbers contains 7 elements: { 3 4 5 6 7 8 9 } +// lowNumbers SymmetricExceptWith highNumbers... +// lowNumbers contains 7 elements: { 0 1 2 8 7 6 9 } +// +// diff --git a/snippets/fsharp/System.Collections.Generic/HashSetT/SymmetricExceptWith/fs.fsproj b/snippets/fsharp/System.Collections.Generic/HashSetT/SymmetricExceptWith/fs.fsproj new file mode 100644 index 00000000000..99d4f2bb01e --- /dev/null +++ b/snippets/fsharp/System.Collections.Generic/HashSetT/SymmetricExceptWith/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/xml/System.Collections.Generic/HashSet`1.xml b/xml/System.Collections.Generic/HashSet`1.xml index 509af9003b5..809097389bd 100644 --- a/xml/System.Collections.Generic/HashSet`1.xml +++ b/xml/System.Collections.Generic/HashSet`1.xml @@ -134,6 +134,7 @@ The following example demonstrates how to merge two disparate sets. This example creates two objects and populates them with even and odd numbers, respectively. A third object is created from the set that contains the even numbers. The example then calls the method, which adds the odd number set to the third set. :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/HashSetT/Overview/Program.cs" interactive="try-dotnet-method" id="Snippet01"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/HashSetT/Overview/Program.fs" id="Snippet01"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Collections.Generic.HashSet_UnionWith/vb/Program.vb" id="Snippet01"::: ]]> @@ -200,6 +201,7 @@ The following example demonstrates how to merge two disparate sets. This example The following example demonstrates how to create and populate two objects. This example is part of a larger example provided for the method. :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/HashSetT/Overview/Program.cs" id="Snippet03"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/HashSetT/Overview/Program.fs" id="Snippet03"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Collections.Generic.HashSet_UnionWith/vb/Program.vb" id="Snippet03"::: ]]> @@ -260,6 +262,7 @@ The following example demonstrates how to merge two disparate sets. This example The following example shows how to create a collection from an existing set. In this example, two sets are created with even and odd integers, respectively. A third object is then created from the even integer set. :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/HashSetT/Overview/Program.cs" interactive="try-dotnet-method" id="Snippet01"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/HashSetT/Overview/Program.fs" id="Snippet01"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Collections.Generic.HashSet_UnionWith/vb/Program.vb" id="Snippet02"::: ]]> @@ -434,6 +437,7 @@ The following example demonstrates how to merge two disparate sets. This example :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Collections.Generic.HashSet_ExceptWith/cpp/source2.cpp" id="Snippet03"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/HashSetT/.ctor/source2.cs" interactive="try-dotnet-method" id="Snippet03"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/HashSetT/.ctor/source2.fs" id="Snippet03"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Collections.Generic.HashSet_ExceptWith/vb/source2.vb" id="Snippet03"::: ]]> @@ -626,6 +630,7 @@ The following example demonstrates how to merge two disparate sets. This example The following example demonstrates how to create and populate two objects. This example is part of a larger example provided for the method. :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/HashSetT/Overview/Program.cs" id="Snippet03"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/HashSetT/Overview/Program.fs" id="Snippet03"::: ]]> @@ -713,6 +718,7 @@ The following example demonstrates how to merge two disparate sets. This example The following example creates and populates a collection, then clears it and releases the memory referenced by the collection. :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/HashSetT/Clear/Program.cs" interactive="try-dotnet-method" id="Snippet01"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/HashSetT/Clear/Program.fs" id="Snippet01"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Collections.Generic.HashSet_Clear/vb/Program.vb" id="Snippet01"::: ]]> @@ -832,6 +838,7 @@ The following example demonstrates how to merge two disparate sets. This example The following example demonstrates how to remove values from a collection using the method. In this example, the method verifies that the set contains a value before removing it. :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/HashSetT/Contains/Program.cs" interactive="try-dotnet-method" id="Snippet02"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/HashSetT/Contains/Program.fs" id="Snippet02"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Collections.Generic.HashSet_RemoveWhere/vb/Program.vb" id="Snippet02"::: ]]> @@ -1097,6 +1104,7 @@ The following example demonstrates how to merge two disparate sets. This example The following example demonstrates how to create, populate, and manipulate two objects. In this example, both the contents of the set and display to the console. :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/HashSetT/Overview/Program.cs" interactive="try-dotnet-method" id="Snippet01"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/HashSetT/Overview/Program.fs" id="Snippet01"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Collections.Generic.HashSet_UnionWith/vb/Program.vb" id="Snippet01"::: ]]> @@ -1254,6 +1262,7 @@ The following example demonstrates how to merge two disparate sets. This example :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Collections.Generic.HashSet_ExceptWith/cpp/program.cpp" id="Snippet02"::: :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/HashSetT/.ctor/Program.cs" interactive="try-dotnet-method" id="Snippet02"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/HashSetT/.ctor/Program.fs" id="Snippet02"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Collections.Generic.HashSet_ExceptWith/vb/Program.vb" id="Snippet02"::: ]]> @@ -1534,6 +1543,7 @@ The following example demonstrates how to merge two disparate sets. This example The following example creates two disparate objects and compares them to each other. In this example, `lowNumbers` is both a subset and a proper subset of `allNumbers` until `allNumbers` is modified, using the method, to contain only values that are present in both sets. Once `allNumbers` and `lowNumbers` are identical, `lowNumbers` is still a subset of `allNumbers` but is no longer a proper subset. :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/HashSetT/IsProperSubsetOf/Program.cs" interactive="try-dotnet-method" id="Snippet02"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/HashSetT/IsProperSubsetOf/Program.fs" id="Snippet02"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Collections.Generic.HashSet_boolMethods/vb/Program.vb" id="Snippet02"::: ]]> @@ -1614,6 +1624,7 @@ The following example demonstrates how to merge two disparate sets. This example The following example creates two disparate objects and compares them to each other. In this example, `allNumbers` is both a superset and a proper superset of `lowNumbers` until `allNumbers` is modified, using the method, to contain only values that are present in both sets. Once `allNumbers` and `lowNumbers` are identical, `allNumbers` is still a superset of `lowNumbers` but is no longer a proper superset. :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/HashSetT/IsProperSubsetOf/Program.cs" interactive="try-dotnet-method" id="Snippet02"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/HashSetT/IsProperSubsetOf/Program.fs" id="Snippet02"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Collections.Generic.HashSet_boolMethods/vb/Program.vb" id="Snippet02"::: ]]> @@ -1694,6 +1705,7 @@ The following example demonstrates how to merge two disparate sets. This example The following example creates two disparate objects and compares them to each other. In this example, `lowNumbers` is both a subset and a proper subset of `allNumbers` until `allNumbers` is modified, using the method, to contain only values that are present in both sets. Once `allNumbers` and `lowNumbers` are identical, `lowNumbers` is still a subset of `allNumbers` but is no longer a proper subset. :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/HashSetT/IsProperSubsetOf/Program.cs" interactive="try-dotnet-method" id="Snippet02"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/HashSetT/IsProperSubsetOf/Program.fs" id="Snippet02"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Collections.Generic.HashSet_boolMethods/vb/Program.vb" id="Snippet02"::: ]]> @@ -1768,6 +1780,7 @@ The following example demonstrates how to merge two disparate sets. This example The following example creates two disparate objects and compares them to each other. In this example, `allNumbers` is both a superset and a proper superset of `lowNumbers` until `allNumbers` is modified, using the method, to contain only values that are present in both sets. Once `allNumbers` and `lowNumbers` are identical, `allNumbers` is still a superset of `lowNumbers` but is no longer a proper superset. :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/HashSetT/IsProperSubsetOf/Program.cs" interactive="try-dotnet-method" id="Snippet02"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/HashSetT/IsProperSubsetOf/Program.fs" id="Snippet02"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Collections.Generic.HashSet_boolMethods/vb/Program.vb" id="Snippet02"::: ]]> @@ -1898,6 +1911,7 @@ The following example demonstrates how to merge two disparate sets. This example The following example creates two disparate objects and compares them to each another. In this example, `allNumbers` and `lowNumbers` are shown to share common elements using the method. :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/HashSetT/IsProperSubsetOf/Program.cs" interactive="try-dotnet-method" id="Snippet02"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/HashSetT/IsProperSubsetOf/Program.fs" id="Snippet02"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Collections.Generic.HashSet_boolMethods/vb/Program.vb" id="Snippet02"::: ]]> @@ -1966,6 +1980,7 @@ The following example demonstrates how to merge two disparate sets. This example The following example demonstrates how to remove values from a collection using the method. In this example, zero is arbitrarily removed from the collection. :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/HashSetT/Contains/Program.cs" interactive="try-dotnet-method" id="Snippet02"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/HashSetT/Contains/Program.fs" id="Snippet02"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Collections.Generic.HashSet_RemoveWhere/vb/Program.vb" id="Snippet02"::: ]]> @@ -2026,6 +2041,7 @@ The following example demonstrates how to merge two disparate sets. This example The following example demonstrates how to remove values from a collection using the method. In this example, all odd integers are removed from the collection as specified by the `match` delegate. :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/HashSetT/Contains/Program.cs" interactive="try-dotnet-method" id="Snippet02"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/HashSetT/Contains/Program.fs" id="Snippet02"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Collections.Generic.HashSet_RemoveWhere/vb/Program.vb" id="Snippet02"::: ]]> @@ -2104,6 +2120,7 @@ The following example demonstrates how to merge two disparate sets. This example The following example creates two disparate objects and compares them to each another. Initially, the two sets are not equal, which is demonstrated by using the method. The `allNumbers` object is then modified, after which the sets are equal. :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/HashSetT/IsProperSubsetOf/Program.cs" interactive="try-dotnet-method" id="Snippet02"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/HashSetT/IsProperSubsetOf/Program.fs" id="Snippet02"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Collections.Generic.HashSet_boolMethods/vb/Program.vb" id="Snippet02"::: ]]> @@ -2177,6 +2194,7 @@ The following example demonstrates how to merge two disparate sets. This example The following example creates two collections with overlapping sets of data. The set that contains the lower values is then modified, using the method, to contain only the values that are not present in both sets. :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/HashSetT/SymmetricExceptWith/Program.cs" interactive="try-dotnet-method" id="Snippet02"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/HashSetT/SymmetricExceptWith/Program.fs" id="Snippet02"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Collections.Generic.HashSet_SymmetricExceptWith/vb/Program.vb" id="Snippet02"::: ]]> @@ -2482,6 +2500,7 @@ The following example demonstrates how to merge two disparate sets. This example The following example creates and populates a collection, and then clears the collection and releases the memory referenced by it. :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/HashSetT/Clear/Program.cs" interactive="try-dotnet-method" id="Snippet01"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/HashSetT/Clear/Program.fs" id="Snippet01"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Collections.Generic.HashSet_Clear/vb/Program.vb" id="Snippet01"::: ]]> @@ -2633,6 +2652,7 @@ The following example demonstrates how to merge two disparate sets. This example The following example demonstrates how to merge two disparate sets. This example creates two objects, and populates them with even and odd numbers, respectively. A third object is created from the set that contains the even numbers. The example then calls the method, which adds the odd number set to the third set. :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/HashSetT/Overview/Program.cs" interactive="try-dotnet-method" id="Snippet01"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/HashSetT/Overview/Program.fs" id="Snippet01"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Collections.Generic.HashSet_UnionWith/vb/Program.vb" id="Snippet01"::: ]]> From 3bff60e62d618c647fabb989087c3d7511a1cbe0 Mon Sep 17 00:00:00 2001 From: Albert Du <52804499+albert-du@users.noreply.github.com> Date: Mon, 24 Jun 2024 07:28:48 -0700 Subject: [PATCH 08/10] F# snippets for ComparerT (#10054) --- .../ComparerT/Overview/fs.fsproj | 10 ++ .../ComparerT/Overview/program.fs | 129 ++++++++++++++++++ xml/System.Collections.Generic/Comparer`1.xml | 4 + 3 files changed, 143 insertions(+) create mode 100644 snippets/fsharp/System.Collections.Generic/ComparerT/Overview/fs.fsproj create mode 100644 snippets/fsharp/System.Collections.Generic/ComparerT/Overview/program.fs diff --git a/snippets/fsharp/System.Collections.Generic/ComparerT/Overview/fs.fsproj b/snippets/fsharp/System.Collections.Generic/ComparerT/Overview/fs.fsproj new file mode 100644 index 00000000000..bdaff5e1367 --- /dev/null +++ b/snippets/fsharp/System.Collections.Generic/ComparerT/Overview/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net8.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System.Collections.Generic/ComparerT/Overview/program.fs b/snippets/fsharp/System.Collections.Generic/ComparerT/Overview/program.fs new file mode 100644 index 00000000000..fef3fb793b0 --- /dev/null +++ b/snippets/fsharp/System.Collections.Generic/ComparerT/Overview/program.fs @@ -0,0 +1,129 @@ +// +open System +open System.Collections.Generic + +// +type Box(h, l, w) = + member val Height: int = h with get + member val Length: int = l with get + member val Width: int = w with get + + interface IComparable with + member this.CompareTo(other) = + // Compares Height, Length, and Width. + if this.Height.CompareTo other.Height <> 0 then + this.Height.CompareTo other.Height + elif this.Length.CompareTo other.Length <> 0 then + this.Length.CompareTo other.Length + elif this.Width.CompareTo other.Width <> 0 then + this.Width.CompareTo other.Width + else + 0 +// + +// +type BoxLengthFirst() = + inherit Comparer() + + // + // Compares by Length, Height, and Width. + override _.Compare(x: Box, y: Box) = + if x.Length.CompareTo y.Length <> 0 then + x.Length.CompareTo y.Length + elif x.Height.CompareTo y.Height <> 0 then + x.Height.CompareTo y.Height + elif x.Width.CompareTo y.Width <> 0 then + x.Width.CompareTo y.Width + else + 0 +// +// + +// +let boxes = ResizeArray() +boxes.Add(Box(4, 20, 14)) +boxes.Add(Box(12, 12, 12)) +boxes.Add(Box(8, 20, 10)) +boxes.Add(Box(6, 10, 2)) +boxes.Add(Box(2, 8, 4)) +boxes.Add(Box(2, 6, 8)) +boxes.Add(Box(4, 12, 20)) +boxes.Add(Box(18, 10, 4)) +boxes.Add(Box(24, 4, 18)) +boxes.Add(Box(10, 4, 16)) +boxes.Add(Box(10, 2, 10)) +boxes.Add(Box(6, 18, 2)) +boxes.Add(Box(8, 12, 4)) +boxes.Add(Box(12, 10, 8)) +boxes.Add(Box(14, 6, 6)) +boxes.Add(Box(16, 6, 16)) +boxes.Add(Box(2, 8, 12)) +boxes.Add(Box(4, 24, 8)) +boxes.Add(Box(8, 6, 20)) +boxes.Add(Box(18, 18, 12)) + +// Sort by an Comparer implementation that sorts +// first by the length. +boxes.Sort(BoxLengthFirst()) + +printfn "H - L - W" +printfn "==========" + +for bx in boxes do + printfn $"{bx.Height}\t{bx.Length}\t{bx.Width}" +// + +printfn "" +printfn "H - L - W" +printfn "==========" + +// +// Get the default comparer that +// sorts first by the height. +let defComp = Comparer.Default + +// Calling Boxes.Sort() with no parameter +// is the same as calling boxes.Sort defComp +// because they are both using the default comparer. +boxes.Sort() + +for bx in boxes do + printfn $"{bx.Height}\t{bx.Length}\t{bx.Width}" +// + +// + +// This explicit interface implementation +// compares first by the length. +// Returns -1 because the length of BoxA +// is less than the length of BoxB. +let LengthFirst = BoxLengthFirst() + +let bc = LengthFirst :> Comparer + +let BoxA = Box(2, 6, 8) +let BoxB = Box(10, 12, 14) +let x = LengthFirst.Compare(BoxA, BoxB) +printfn $"\n{x}" +// + +// +// This class is not demonstrated in the Main method +// and is provided only to show how to implement +// the interface. It is recommended to derive +// from Comparer instead of implementing IComparer. +type BoxComp() = + interface IComparer with + // Compares by Height, Length, and Width. + member _.Compare(x: Box, y: Box) = + if x.Height.CompareTo(y.Height) <> 0 then + x.Height.CompareTo(y.Height) + elif x.Length.CompareTo(y.Length) <> 0 then + x.Length.CompareTo(y.Length) + elif x.Width.CompareTo(y.Width) <> 0 then + x.Width.CompareTo(y.Width) + else + 0 +// + +// diff --git a/xml/System.Collections.Generic/Comparer`1.xml b/xml/System.Collections.Generic/Comparer`1.xml index 90a4997bca3..142e8e42e66 100644 --- a/xml/System.Collections.Generic/Comparer`1.xml +++ b/xml/System.Collections.Generic/Comparer`1.xml @@ -97,6 +97,7 @@ The following example derives a class, `BoxLengthFirst`, from the class. This comparer compares two objects of type `Box`. It sorts them first by length, then by height, and then by width. The `Box` class implements the interface to control the default comparison between two `Box` objects. This default implementation sorts first by height, then by length, and then by width. The example shows the differences between the two comparisons by sorting a list of `Box` objects first by using the `BoxLengthFirst` comparer and then by using the default comparer. :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/ComparerT/Overview/program.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/ComparerT/Overview/program.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.collections.generic.boxcompare/vb/program.vb" id="Snippet1"::: ]]> @@ -250,6 +251,7 @@ The following example defines a comparer of `Box` objects that can be used instead of the default comparer. This example is part of a larger example provided for the class. :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/ComparerT/Overview/program.cs" id="Snippet5"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/ComparerT/Overview/program.fs" id="Snippet5"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.collections.generic.boxcompare/vb/program.vb" id="Snippet5"::: ]]> @@ -367,6 +369,7 @@ The following example shows how to use the property to get an object that performs the default comparison. This example is part of a larger example provided for the class. :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/ComparerT/Overview/program.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/ComparerT/Overview/program.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.collections.generic.boxcompare/vb/program.vb" id="Snippet3"::: ]]> @@ -461,6 +464,7 @@ The following example shows how to use the method to compare two objects. This example is part of a larger example provided for the class. :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/ComparerT/Overview/program.cs" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/ComparerT/Overview/program.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.collections.generic.boxcompare/vb/program.vb" id="Snippet4"::: ]]> From 15f926f0ef7ab4a75c179f8c38052ff6a4248909 Mon Sep 17 00:00:00 2001 From: Tarek Mahmoud Sayed Date: Mon, 24 Jun 2024 10:53:11 -0700 Subject: [PATCH 09/10] Apply suggestions from code review Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com> --- xml/Microsoft.Extensions.Options/IOptionsMonitor`1.xml | 2 +- xml/Microsoft.Extensions.Options/IOptionsSnapshot`1.xml | 2 +- xml/Microsoft.Extensions.Options/OptionsManager`1.xml | 2 +- xml/Microsoft.Extensions.Options/OptionsMonitor`1.xml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/xml/Microsoft.Extensions.Options/IOptionsMonitor`1.xml b/xml/Microsoft.Extensions.Options/IOptionsMonitor`1.xml index ec3046cf791..6b017dbe45f 100644 --- a/xml/Microsoft.Extensions.Options/IOptionsMonitor`1.xml +++ b/xml/Microsoft.Extensions.Options/IOptionsMonitor`1.xml @@ -97,7 +97,7 @@ - The name of the instance. Uses if is provided. + The name of the instance. If , , which is the empty string, is used. Returns a configured instance with the given name. The instance that matches the given . To be added. diff --git a/xml/Microsoft.Extensions.Options/IOptionsSnapshot`1.xml b/xml/Microsoft.Extensions.Options/IOptionsSnapshot`1.xml index 7f80d5fcede..1cc48fcfa86 100644 --- a/xml/Microsoft.Extensions.Options/IOptionsSnapshot`1.xml +++ b/xml/Microsoft.Extensions.Options/IOptionsSnapshot`1.xml @@ -76,7 +76,7 @@ - The name of the instance. Uses if is provided. + The name of the instance. If , , which is the empty string, is used. Returns a configured instance with the given name. The instance that matches the given . To be added. diff --git a/xml/Microsoft.Extensions.Options/OptionsManager`1.xml b/xml/Microsoft.Extensions.Options/OptionsManager`1.xml index 9d1fa6c6e1c..2c2ef367c88 100644 --- a/xml/Microsoft.Extensions.Options/OptionsManager`1.xml +++ b/xml/Microsoft.Extensions.Options/OptionsManager`1.xml @@ -112,7 +112,7 @@ - The name of the instance. Uses if is provided. + The name of the instance. If , , which is the empty string, is used. Returns a configured instance with the given . The instance that matches the given . To be added. diff --git a/xml/Microsoft.Extensions.Options/OptionsMonitor`1.xml b/xml/Microsoft.Extensions.Options/OptionsMonitor`1.xml index acec5e309a7..3fec5c51c70 100644 --- a/xml/Microsoft.Extensions.Options/OptionsMonitor`1.xml +++ b/xml/Microsoft.Extensions.Options/OptionsMonitor`1.xml @@ -167,7 +167,7 @@ - The name of the instance. Uses if is provided. + The name of the instance. If , , which is the empty string, is used. Returns a configured instance with the given . The instance that matches the given . To be added. From d6d38e405484148855192144a74024519c11b731 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Tue, 25 Jun 2024 05:22:12 -0700 Subject: [PATCH 10/10] Update AssesmblyBuilder.DefineDynamicModule to call out that .NET Core/5+ only supports one module per assembly (#10057) * Update AssesmblyBuilder.DefineDynamicModule to call out that .NET Core/5+ only supports one module per assembly * Update xml/System.Reflection.Emit/AssemblyBuilder.xml Co-authored-by: Jan Kotas --------- Co-authored-by: Jan Kotas --- xml/System.Reflection.Emit/AssemblyBuilder.xml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/xml/System.Reflection.Emit/AssemblyBuilder.xml b/xml/System.Reflection.Emit/AssemblyBuilder.xml index aeab14be3cf..c2c048fcb2c 100644 --- a/xml/System.Reflection.Emit/AssemblyBuilder.xml +++ b/xml/System.Reflection.Emit/AssemblyBuilder.xml @@ -576,7 +576,9 @@ The following code example shows how to define and use a dynamic assembly. The e . @@ -607,9 +609,15 @@ The following code example shows how to define and use a dynamic assembly. The e -or- - The length of is greater than the system-defined maximum length. + The length of is greater than the system-defined maximum length. + + -or- + + .NET Framework only: A module with the same has already been defined in this assembly. + is . + .NET Core and .NET 5+ only: A dynamic module has already been defined in this assembly. The caller does not have the required permission. The assembly for default symbol writer cannot be loaded. @@ -916,7 +924,7 @@ The following code example shows how to define and use a dynamic assembly. The e The name of the dynamic module. When overridden in a derived class, defines a dynamic module in this assembly. A representing the defined dynamic module. - .NET Core supports only one module. + .NET Core and .NET 5+ support only one module per assembly. @@ -1772,7 +1780,7 @@ The following code example shows how to define and use a dynamic assembly. The e The name of the requested dynamic module. When overridden in a derived class, returns the dynamic module with the specified name. A representing the requested dynamic module. - .NET Core supports only one module. + .NET Core and .NET 5+ support only one module per assembly..