UIntPtr.Subtraction(UIntPtr, Int32) UIntPtr.Subtraction(UIntPtr, Int32) UIntPtr.Subtraction(UIntPtr, Int32) UIntPtr.Subtraction(UIntPtr, Int32) Operator

定義

將不帶正負號指標的值減去位移。Subtracts an offset from the value of an unsigned pointer.

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

參數

pointer
UIntPtr UIntPtr UIntPtr UIntPtr

要減去位移的不帶正負號指標。The unsigned pointer to subtract the offset from.

offset
Int32 Int32 Int32 Int32

要減去的位移。The offset to subtract.

傳回

新的不帶正負號指標,反映將 offset 減去 pointer 的結果。A new unsigned pointer that reflects the subtraction of offset from pointer.

備註

方法會定義UIntPtr物件的減法運算。 SubtractionThe Subtraction method defines the subtraction operation for UIntPtr objects. 它可啟用如下所示的程式碼。It enables code such as the following.

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 = ptr - ctr;
   Console.Write("{0}   ", newPtr);
}
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

不支援自訂運算子的語言可以改為Subtract呼叫方法。Languages that do not support custom operators can call the Subtract method instead.

如果結果太小而無法表示為指定平臺上的指標,則減法運算不會擲回例外狀況。The subtraction operation does not throw an exception if the result is too small to represent as a pointer on the specified platform. 相反地,它是在未檢查的內容中執行。Instead, it is performed in an unchecked context.

適用於

另請參閱