共用方式為


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

新的不帶正負號整數,反映 從 pointeroffset 法。

範例

下列範例會具現化 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 方法不會擲回例外狀況。 相反地,減法運算會在未核取的內容中執行。

不支援運算子多載或自訂運算子的語言,可以使用這個方法從指標的值減去位移。

適用於

另請參閱