IntPtr.Addition(IntPtr, Int32) 연산자
정의
포인터의 값에 오프셋을 더합니다.Adds an offset to the value of a pointer.
public:
static IntPtr operator +(IntPtr pointer, int offset);
public static IntPtr operator + (IntPtr pointer, int offset);
static member ( + ) : nativeint * int -> nativeint
Public Shared Operator + (pointer As IntPtr, offset As Integer) As IntPtr
매개 변수
- pointer
- IntPtr
오프셋을 더할 포인터입니다.The pointer to add the offset to.
- offset
- Int32
더할 오프셋입니다.The offset to add.
반환
offset
에 pointer
더하기를 반영하는 새 포인터입니다.A new pointer that reflects the addition of offset
to pointer
.
설명
Addition메서드는 개체에 대 한 추가 작업을 정의 합니다 IntPtr .The Addition method defines the addition operation for IntPtr objects. 다음과 같은 코드를 사용할 수 있습니다.It enables code such as the following.
int[] arr = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20 };
unsafe {
fixed(int* parr = arr)
{
IntPtr ptr = new IntPtr(parr);
for (int ctr = 0; ctr < arr.Length; ctr++)
{
IntPtr newPtr = ptr + ctr * sizeof(Int32);
Console.Write("{0} ", Marshal.ReadInt32(newPtr));
}
}
}
// The example displays the following output:
// 2 4 6 8 10 12 14 16 18 20
Dim arr() As Integer = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20 }
Dim ptr As IntPtr = Marshal.UnsafeAddrOfPinnedArrayElement(arr, 0)
For ctr As Integer = 0 To arr.Length - 1
Dim newPtr As IntPtr = ptr + ctr * Len(arr(0))
Console.WriteLine("{0} ", Marshal.ReadInt32(newPtr))
Next
' The example displays the following output:
' 2 4 6 8 10 12 14 16 18 20
사용자 지정 연산자를 지원 하지 않는 언어는 대신 메서드를 호출할 수 있습니다 Add .Languages that do not support custom operators can call the Add method instead.
추가 작업은 결과가 너무 커서 지정 된 플랫폼에 대 한 포인터로 나타낼 수 없는 경우 예외를 throw 하지 않습니다.The addition operation does not throw an exception if the result is too large to represent as a pointer on the specified platform. 대신, unchecked 컨텍스트에서 수행 됩니다.Instead, it is performed in an unchecked context.
이 연산자에 대 한 해당 메서드는 IntPtr.Add(IntPtr, Int32)The equivalent method for this operator is IntPtr.Add(IntPtr, Int32)