UIntPtr.Add(UIntPtr, Int32) 메서드

정의

부호 없는 정수에 오프셋을 추가합니다.

public:
 static UIntPtr Add(UIntPtr pointer, int offset);
public static UIntPtr Add (UIntPtr pointer, int offset);
static member Add : unativeint * int -> unativeint
Public Shared Function Add (pointer As UIntPtr, offset As Integer) As UIntPtr

매개 변수

pointer
UIntPtr

unativeint

오프셋을 추가할 부호 없는 정수입니다.

offset
Int32

더할 오프셋입니다.

반환

UIntPtr

unativeint

에 대한 추가 offset pointer를 반영하는 부호 없는 새 정수입니다.

예제

다음 예제에서는 10개 요소 배열의 시작을 가리키는 개체를 인스턴스화 UIntPtr 한 다음, 메서드를 Add 호출하여 배열의 요소를 반복합니다.

using System;

public class Example
{
   public static void Main()
   {
      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 = UIntPtr.Add(ptr, ctr);
         Console.Write("{0}   ", newPtr);
      }      
   }
}
// The example displays the following output:
//       1   2   3   4   5   6   7   8   9   10
open System

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 = UIntPtr.Add(ptr, i)
    printf $"{newPtr}   "
// The example displays the following output:
//       1   2   3   4   5   6   7   8   9   10
Module Example
   Public Sub Main()
      Dim arr() As Integer = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
      Dim ptr As UIntPtr = CType(arr(0), UIntPtr)
      For ctr As Integer= 0 To arr.Length - 1
         Dim newPtr As UIntPtr = UIntPtr.Add(ptr, ctr)
         Console.Write("{0}   ", newPtr)
      Next
   End Sub
End Module
' The example displays the following output:
'       1   2   3   4   5   6   7   8   9   10

설명

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

연산자 오버로드 또는 사용자 지정 연산자를 지원하지 않는 언어는 이 메서드를 사용하여 포인터 값에 오프셋을 추가할 수 있습니다.

적용 대상

추가 정보