Language

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

定義

符号なし整数からオフセットを減算します。

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

パラメーター

pointer
UIntPtr

unativeint

オフセットを減算する符号なし整数。

offset
Int32

減算するオフセット。

返品

UIntPtr

unativeint

offsetからのpointerの減算を反映する新しい符号なし整数。

例

次の例では、10 要素配列の末尾を指す IntPtr オブジェクトをインスタンス化し、 Subtract メソッドを呼び出して配列内の要素を逆の順序で反復処理します。

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

注釈

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

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

適用対象

こちらもご覧ください