Skip to content

Commit b38f019

Browse files
authored
UIntPtr F# snippets (#8052)
1 parent 27bda10 commit b38f019

File tree

8 files changed

+79
-0
lines changed

8 files changed

+79
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// <Snippet1>
2+
open System
3+
4+
let arr = [| 1; 2; 3; 4; 5; 6; 7; 8; 9; 10 |]
5+
let ptr = UIntPtr(uint arr[0])
6+
for i = 0 to arr.Length - 1 do
7+
let newPtr = UIntPtr.Add(ptr, i)
8+
printf $"{newPtr} "
9+
// The example displays the following output:
10+
// 1 2 3 4 5 6 7 8 9 10
11+
// </Snippet1>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net6.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<Compile Include="add1.fs" />
9+
</ItemGroup>
10+
</Project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net6.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<Compile Include="subtract1.fs" />
9+
</ItemGroup>
10+
</Project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// <Snippet1>
2+
open System
3+
4+
let arr = [| 1; 2; 3; 4; 5; 6; 7; 8; 9; 10 |]
5+
let ptr = UIntPtr(uint arr[arr.GetUpperBound 0])
6+
for i = 0 to arr.GetUpperBound 0 do
7+
let newPtr = UIntPtr.Subtract(ptr, i)
8+
printf $"{newPtr} "
9+
// The example displays the following output:
10+
// 10 9 8 7 6 5 4 3 2 1
11+
// </Snippet1>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net6.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<Compile Include="op_addition1.fs" />
9+
<Compile Include="op_subtraction1.fs" />
10+
</ItemGroup>
11+
</Project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module op_addition1
2+
3+
open System
4+
5+
// <Snippet1>
6+
let arr = [| 1; 2; 3; 4; 5; 6; 7; 8; 9; 10 |]
7+
let ptr = UIntPtr(uint arr[0])
8+
for i = 0 to arr.Length - 1 do
9+
let newPtr = ptr + UIntPtr(uint i)
10+
printfn $"{newPtr}"
11+
// </Snippet1>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module op_subtraction
2+
3+
open System
4+
5+
// <Snippet2>
6+
let arr = [| 1; 2; 3; 4; 5; 6; 7; 8; 9; 10 |]
7+
let ptr = UIntPtr(uint arr[arr.GetUpperBound 0])
8+
for i = 0 to arr.GetUpperBound 0 do
9+
let newPtr = ptr - UIntPtr(uint i)
10+
printf $"{newPtr} "
11+
// </Snippet2>

xml/System/UIntPtr.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@
495495
The following example instantiates a <xref:System.UIntPtr> object that points to the beginning of a ten-element array, and then calls the <xref:System.UIntPtr.Add%2A> method to iterate the elements in the array.
496496
497497
:::code language="csharp" source="~/snippets/csharp/System/UIntPtr/Add/add1.cs" id="Snippet1":::
498+
:::code language="fsharp" source="~/snippets/fsharp/System/UIntPtr/Add/add1.fs" id="Snippet1":::
498499
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.uintptr.add/vb/add1.vb" id="Snippet1":::
499500
500501
]]></format>
@@ -877,6 +878,7 @@ For <xref:System.IFloatingPoint`1> this method matches the IEEE 754:2019 `minimu
877878
The <xref:System.UIntPtr.op_Addition%2A> method defines the addition operation for <xref:System.UIntPtr> objects. It enables code such as the following.
878879
879880
:::code language="csharp" source="~/snippets/csharp/System/UIntPtr/op_Addition/op_addition1.cs" id="Snippet1":::
881+
:::code language="fsharp" source="~/snippets/fsharp/System/UIntPtr/op_Addition/op_addition1.fs" id="Snippet1":::
880882
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.uintptr.op_addition/vb/op_addition1.vb" id="Snippet1":::
881883
882884
Languages that do not support custom operators can call the <xref:System.UIntPtr.Add%2A> method instead.
@@ -1388,6 +1390,7 @@ For <xref:System.IFloatingPoint`1> this method matches the IEEE 754:2019 `minimu
13881390
The <xref:System.UIntPtr.op_Subtraction%2A> method defines the subtraction operation for <xref:System.UIntPtr> objects. It enables code such as the following.
13891391
13901392
:::code language="csharp" source="~/snippets/csharp/System/UIntPtr/op_Addition/op_subtraction1.cs" id="Snippet2":::
1393+
:::code language="fsharp" source="~/snippets/fsharp/System/UIntPtr/op_Addition/op_subtraction1.fs" id="Snippet2":::
13911394
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.uintptr.op_addition/vb/op_subtraction1.vb" id="Snippet2":::
13921395
13931396
Languages that do not support custom operators can call the <xref:System.UIntPtr.Subtract%2A> method instead.
@@ -1720,6 +1723,7 @@ For <xref:System.IFloatingPoint`1> this method matches the IEEE 754:2019 `minimu
17201723
The following example instantiates an <xref:System.IntPtr> object that points to the end of a ten-element array, and then calls the <xref:System.IntPtr.Subtract%2A> method to iterate the elements in the array in reverse order.
17211724
17221725
:::code language="csharp" source="~/snippets/csharp/System/UIntPtr/Subtract/subtract1.cs" id="Snippet1":::
1726+
:::code language="fsharp" source="~/snippets/fsharp/System/UIntPtr/Subtract/subtract1.fs" id="Snippet1":::
17231727
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.uintptr.subtract/vb/subtract1.vb" id="Snippet1":::
17241728
17251729
]]></format>

0 commit comments

Comments
 (0)