UIntPtr.Addition(UIntPtr, Int32) 運算子

定義

將位移加入至不帶正負號的整數。

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

unativeint

要加入位移的不帶正負號整數。

offset
Int32

要加上的位移。

傳回

UIntPtr

unativeint

新的不帶正負號整數,反映 offset 加入 至 pointer

備註

方法 Addition 會定義 物件的加法作業 UIntPtr 。 它會啟用下列程式碼。

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 = ptr + ctr;
   Console.WriteLine(newPtr);
}
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}"
Dim arr() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
Dim ptr = CType(arr(0), UIntPtr)
For ctr As Integer = 0 To arr.Length - 1
   Dim newPtr As UIntPtr = ptr + ctr
   Console.WriteLine(newPtr)
Next

不支援自訂運算子的語言可以改為呼叫 Add 方法。

如果結果太大而無法表示為執行程式中不帶正負號的整數,則加法運算不會擲回例外狀況。 相反地,它會在未核取的內容中執行。

從版本 11 開始且以 .NET 7 或更新版本的執行時間為目標的 C# 中,此 API 只能透過反映來存取。 加法運算子是由語言直接辨識,而且會遵循加法運算的一般語言行為,包括在結果太大而無法表示時,內容中的 checked 溢位。

這個運算子 UIntPtr.Add(UIntPtr, Int32) 的對等方法是 。

適用於

另請參閱