UIntPtr.Subtract(UIntPtr, Int32) 메서드

정의

부호 없는 정수에서 오프셋을 뺍니다.

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

매개 변수

pointer
UIntPtr

unativeint

오프셋을 뺄 부호 없는 정수입니다.

offset
Int32

뺄 오프셋입니다.

반환

UIntPtr

unativeint

에서의 빼기를 offset pointer반영하는 부호 없는 새 정수입니다.

예제

다음 예제에서는 10개 요소 배열의 끝을 가리키는 개체를 인스턴스화 IntPtr 한 다음 메서드를 호출 Subtract 하여 배열의 요소를 역순으로 반복합니다.

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[arr.GetUpperBound(0)];
      for (int ctr = 0; ctr <= arr.GetUpperBound(0); ctr++)
      {
         UIntPtr newPtr = UIntPtr.Subtract(ptr, ctr);
         Console.Write("{0}   ", newPtr);
      }
   }
}
// The example displays the following output:
//       10   9   8   7   6   5   4   3   2   1
open System

let arr = [| 1; 2; 3; 4; 5; 6; 7; 8; 9; 10 |]
let ptr = UIntPtr(uint arr[arr.GetUpperBound 0])
for i = 0 to arr.GetUpperBound 0 do
    let newPtr = UIntPtr.Subtract(ptr, i)
    printf $"{newPtr}   "
// The example displays the following output:
//       10   9   8   7   6   5   4   3   2   1
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(arr.GetUpperBound(0)), UIntPtr)
      For ctr As Integer= 0 To arr.GetUpperBound(0)
         Dim newPtr As UIntPtr = UIntPtr.Subtract(ptr, ctr)
         Console.Write("{0}   ", newPtr)
      Next
   End Sub
End Module
' The example displays the following output:
'       10   9   8   7   6   5   4   3   2   1

설명

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

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

적용 대상

추가 정보