UIntPtr.Addition(UIntPtr, Int32) 运算符

定义

为无符号指针的值增加偏移量。Adds an offset to 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

要为其增加偏移量的无符号指针。The unsigned pointer to add the offset to.

offset
Int32

要增加的偏移量。The offset to add.

返回

UIntPtr

新的无符号指针,反映向 offset 增加 pointer 的结果。A new unsigned pointer that reflects the addition of offset to pointer.

注解

Addition方法定义对象的加法运算 UIntPtrThe Addition method defines the addition 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[0];
for (int ctr = 0; ctr < arr.Length; ctr++)
{
   UIntPtr newPtr = ptr + ctr;
   Console.WriteLine(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 方法。Languages that do not support custom operators can call the Add method instead.

如果结果太大而无法表示为指定平台上的指针,则加法运算不会引发异常。The addition operation does not throw an exception if the result is too large to represent as a pointer on the specified platform. 相反,它是在未检查的上下文中执行的。Instead, it is performed in an unchecked context.

此运算符的等效方法为 UIntPtr.Add(UIntPtr, Int32)The equivalent method for this operator is UIntPtr.Add(UIntPtr, Int32).

适用于

另请参阅