UIntPtr.Add(UIntPtr, Int32) メソッド

定義

符号なし整数にオフセットを追加します。

public:
 static UIntPtr Add(UIntPtr pointer, int offset);
public static UIntPtr Add(UIntPtr pointer, int offset);
static member Add : unativeint * int -> unativeint
Public Shared Function Add (pointer As UIntPtr, offset As Integer) As UIntPtr

パラメーター

pointer
UIntPtr

unativeint

オフセットを追加する符号なし整数。

offset
Int32

追加するオフセット。

返品

UIntPtr

unativeint

offsetへのpointerの追加を反映する新しい符号なし整数。

次の例では、10 要素配列の先頭を指す UIntPtr オブジェクトをインスタンス化し、 Add メソッドを呼び出して配列内の要素を反復処理します。

using System;

public class Example
{
   public static void Main()
   {
      int[] arr = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
      UIntPtr ptr = (UIntPtr) arr[0];
      for (int ctr = 0; ctr < arr.Length; ctr++)
      {
         UIntPtr newPtr = UIntPtr.Add(ptr, ctr);
         Console.Write("{0}   ", newPtr);
      }      
   }
}
// The example displays the following output:
//       1   2   3   4   5   6   7   8   9   10
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
Module Example
   Public Sub Main()
      Dim arr() As Integer = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
      Dim ptr As UIntPtr = CType(arr(0), UIntPtr)
      For ctr As Integer= 0 To arr.Length - 1
         Dim newPtr As UIntPtr = UIntPtr.Add(ptr, ctr)
         Console.Write("{0}   ", newPtr)
      Next
   End Sub
End Module
' The example displays the following output:
'       1   2   3   4   5   6   7   8   9   10

注釈

結果が大きすぎて実行中のプロセスで符号なし整数として表されない場合、 Add メソッドは例外をスローしません。 代わりに、追加操作はオフのコンテキストで実行されます。

演算子のオーバーロードまたはカスタム演算子をサポートしていない言語では、このメソッドを使用してポインターの値にオフセットを追加できます。

適用対象

こちらもご覧ください