Thanks to visit codestin.com
Credit goes to github.com

Skip to content

System.UIntPtr F# snippets #8052

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions snippets/fsharp/System/UIntPtr/Add/add1.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// <Snippet1>
open System

let arr = [| 1; 2; 3; 4; 5; 6; 7; 8; 9; 10 |]
let ptr = UIntPtr(uint arr[0])
for i = 0 to arr.Length - 1 do
let newPtr = UIntPtr.Add(ptr, i)
printf $"{newPtr} "
// The example displays the following output:
// 1 2 3 4 5 6 7 8 9 10
// </Snippet1>
10 changes: 10 additions & 0 deletions snippets/fsharp/System/UIntPtr/Add/fs.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="add1.fs" />
</ItemGroup>
</Project>
10 changes: 10 additions & 0 deletions snippets/fsharp/System/UIntPtr/Subtract/fs.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="subtract1.fs" />
</ItemGroup>
</Project>
11 changes: 11 additions & 0 deletions snippets/fsharp/System/UIntPtr/Subtract/subtract1.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// <Snippet1>
open System

let arr = [| 1; 2; 3; 4; 5; 6; 7; 8; 9; 10 |]
let ptr = UIntPtr(uint arr[arr.GetUpperBound 0])
for i = 0 to arr.GetUpperBound 0 do
let newPtr = UIntPtr.Subtract(ptr, i)
printf $"{newPtr} "
// The example displays the following output:
// 10 9 8 7 6 5 4 3 2 1
// </Snippet1>
11 changes: 11 additions & 0 deletions snippets/fsharp/System/UIntPtr/op_Addition/fs.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="op_addition1.fs" />
<Compile Include="op_subtraction1.fs" />
</ItemGroup>
</Project>
11 changes: 11 additions & 0 deletions snippets/fsharp/System/UIntPtr/op_Addition/op_addition1.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module op_addition1

open System

// <Snippet1>
let arr = [| 1; 2; 3; 4; 5; 6; 7; 8; 9; 10 |]
let ptr = UIntPtr(uint arr[0])
for i = 0 to arr.Length - 1 do
let newPtr = ptr + UIntPtr(uint i)
printfn $"{newPtr}"
// </Snippet1>
11 changes: 11 additions & 0 deletions snippets/fsharp/System/UIntPtr/op_Addition/op_subtraction1.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module op_subtraction

open System

// <Snippet2>
let arr = [| 1; 2; 3; 4; 5; 6; 7; 8; 9; 10 |]
let ptr = UIntPtr(uint arr[arr.GetUpperBound 0])
for i = 0 to arr.GetUpperBound 0 do
let newPtr = ptr - UIntPtr(uint i)
printf $"{newPtr} "
// </Snippet2>
4 changes: 4 additions & 0 deletions xml/System/UIntPtr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@
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.

:::code language="csharp" source="~/snippets/csharp/System/UIntPtr/Add/add1.cs" id="Snippet1":::
:::code language="fsharp" source="~/snippets/fsharp/System/UIntPtr/Add/add1.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.uintptr.add/vb/add1.vb" id="Snippet1":::

]]></format>
Expand Down Expand Up @@ -877,6 +878,7 @@ For <xref:System.IFloatingPoint`1> this method matches the IEEE 754:2019 `minimu
The <xref:System.UIntPtr.op_Addition%2A> method defines the addition operation for <xref:System.UIntPtr> objects. It enables code such as the following.

:::code language="csharp" source="~/snippets/csharp/System/UIntPtr/op_Addition/op_addition1.cs" id="Snippet1":::
:::code language="fsharp" source="~/snippets/fsharp/System/UIntPtr/op_Addition/op_addition1.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.uintptr.op_addition/vb/op_addition1.vb" id="Snippet1":::

Languages that do not support custom operators can call the <xref:System.UIntPtr.Add%2A> method instead.
Expand Down Expand Up @@ -1388,6 +1390,7 @@ For <xref:System.IFloatingPoint`1> this method matches the IEEE 754:2019 `minimu
The <xref:System.UIntPtr.op_Subtraction%2A> method defines the subtraction operation for <xref:System.UIntPtr> objects. It enables code such as the following.

:::code language="csharp" source="~/snippets/csharp/System/UIntPtr/op_Addition/op_subtraction1.cs" id="Snippet2":::
:::code language="fsharp" source="~/snippets/fsharp/System/UIntPtr/op_Addition/op_subtraction1.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.uintptr.op_addition/vb/op_subtraction1.vb" id="Snippet2":::

Languages that do not support custom operators can call the <xref:System.UIntPtr.Subtract%2A> method instead.
Expand Down Expand Up @@ -1720,6 +1723,7 @@ For <xref:System.IFloatingPoint`1> this method matches the IEEE 754:2019 `minimu
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.

:::code language="csharp" source="~/snippets/csharp/System/UIntPtr/Subtract/subtract1.cs" id="Snippet1":::
:::code language="fsharp" source="~/snippets/fsharp/System/UIntPtr/Subtract/subtract1.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.uintptr.subtract/vb/subtract1.vb" id="Snippet1":::

]]></format>
Expand Down