UIntPtr.Add(UIntPtr, Int32) Metoda

Definicja

Dodaje przesunięcie do niepodpisanej liczby całkowitej.

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

Parametry

pointer
UIntPtr

unativeint

Liczba całkowita bez znaku w celu dodania przesunięcia do.

offset
Int32

Przesunięcie do dodania.

Zwraca

UIntPtr

unativeint

Nowa niepodpisane liczba całkowita, która odzwierciedla dodanie elementu offset do pointerelementu .

Przykłady

Poniższy przykład tworzy wystąpienie UIntPtr obiektu wskazującego początek tablicy dziesięć elementów, a następnie wywołuje Add metodę, aby iterować elementy w tablicy.

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

Uwagi

Metoda Add nie zgłasza wyjątku, jeśli wynik jest zbyt duży, aby reprezentować jako niepodpisane liczby całkowite w procesie wykonywania. Zamiast tego operacja dodawania jest wykonywana w nieznakowanym kontekście.

Języki, które nie obsługują przeciążenia operatora lub operatory niestandardowe, mogą użyć tej metody, aby dodać przesunięcie do wartości wskaźnika.

Dotyczy

Zobacz też