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

一个新的无符号整数,反映 对 pointeroffset加法。

注解

方法 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 开始的 C# 中,面向 .NET 7 或更高版本运行时时,只能通过反射访问此 API。 加法运算符由语言直接识别,并将遵循加法运算的正常语言行为,包括在结果太大而无法表示时在上下文中 checked 溢出。

此运算符 UIntPtr.Add(UIntPtr, Int32)的等效方法是 。

适用于

另请参阅