IntPtr.Addition(IntPtr, Int32) 연산자

정의

부 서명된 정수에 오프셋을 추가합니다.

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

nativeint

오프셋을 추가할 부록 정수입니다.

offset
Int32

더할 오프셋입니다.

반환

IntPtr

nativeint

에 추가 offset pointer된 것을 반영하는 새 부가 정수입니다.

설명

메서드는 Addition 개체에 대한 IntPtr 추가 작업을 정의합니다. 다음과 같은 코드를 사용하도록 설정합니다.

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
#nowarn "9"
open System.Runtime.InteropServices
open FSharp.NativeInterop

[<EntryPoint>]
let main _ =
    let arr =
        [| 2; 4; 6; 8; 10; 12; 14; 16; 18; 20 |]
        
    use parr = fixed arr

    let ptr = NativePtr.toNativeInt parr

    for i = 0 to arr.Length - 1 do
        let newPtr = ptr + nativeint i * nativeint sizeof<int>
        printf $"{Marshal.ReadInt32 newPtr}   "
    0

    // 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 수 있습니다.

결과가 너무 커서 실행 프로세스에서 부가 정수로 나타낼 수 없는 경우 더하기 작업은 예외를 throw하지 않습니다. 대신 확인되지 않은 컨텍스트에서 수행됩니다.

C#에서 버전 11부터 .NET 7 이상 런타임을 대상으로 하는 경우 이 API는 리플렉션을 통해서만 액세스할 수 있습니다. 더하기 연산자는 언어로 직접 인식되며 결과가 너무 커서 나타낼 수 없는 경우 컨텍스트에서 오버플로를 checked 포함하여 추가 작업에 대한 일반적인 언어 동작을 따릅니다.

이 연산자에 대 한 해당 메서드는 IntPtr.Add(IntPtr, Int32)

적용 대상

추가 정보