Redigera

Dela via


Unsafe.AddByteOffset Method

Definition

Overloads

AddByteOffset<T>(T, IntPtr)

Adds a byte offset to the given managed pointer.

AddByteOffset<T>(T, UIntPtr)

Adds a byte offset to the given managed pointer.

AddByteOffset<T>(T, IntPtr)

Source:
Unsafe.cs
Source:
Unsafe.cs
Source:
Unsafe.cs

Adds a byte offset to the given managed pointer.

public:
generic <typename T>
 static T % AddByteOffset(T % source, IntPtr byteOffset);
public static ref T AddByteOffset<T> (ref T source, IntPtr byteOffset);
static member AddByteOffset : 'T * nativeint -> 'T
Public Shared Function AddByteOffset(Of T) (ByRef source As T, byteOffset As IntPtr) As T

Type Parameters

T

The elemental type of the managed pointer.

Parameters

source
T

The managed pointer to add the offset to.

byteOffset
IntPtr

nativeint

The offset to add.

Returns

T

A new managed pointer that reflects the addition of the specified byte offset to the source pointer.

Remarks

The byteOffset parameter is the number of bytes to add to the source pointer. For example, given a source pointer ptr of type ref int, the call Unsafe.AddByteOffset<int>(ref ptr, 20) will return a new pointer whose address points 20 bytes beyond ptr.

If byteOffset is a calculated value rather than a hardcoded literal, callers should consider the possibility of integer overflow. For example, in the call Unsafe.AddByteOffset<int>(ref ptr, a * b), the caller must ensure the intermediate value a * b does not overflow the bounds of IntPtr.

Applies to

AddByteOffset<T>(T, UIntPtr)

Source:
Unsafe.cs
Source:
Unsafe.cs
Source:
Unsafe.cs

Important

This API is not CLS-compliant.

Adds a byte offset to the given managed pointer.

public:
generic <typename T>
 static T % AddByteOffset(T % source, UIntPtr byteOffset);
public static ref T AddByteOffset<T> (ref T source, nuint byteOffset);
[System.CLSCompliant(false)]
public static ref T AddByteOffset<T> (ref T source, UIntPtr byteOffset);
static member AddByteOffset : 'T * unativeint -> 'T
[<System.CLSCompliant(false)>]
static member AddByteOffset : 'T * unativeint -> 'T
Public Shared Function AddByteOffset(Of T) (ByRef source As T, byteOffset As UIntPtr) As T

Type Parameters

T

The elemental type of the managed pointer.

Parameters

source
T

The managed pointer to add the offset to.

byteOffset
UIntPtr

nuint

unativeint

The offset to add.

Returns

T

A new managed pointer that reflects the addition of the specified byte offset to the source pointer.

Attributes

Remarks

The byteOffset parameter is the number of bytes to add to the source pointer. For example, given a source pointer ptr of type ref int, the call Unsafe.AddByteOffset<int>(ref ptr, (nuint)20) will return a new pointer whose address points 20 bytes beyond ptr.

If byteOffset is a calculated value rather than a hardcoded literal, callers should consider the possibility of integer overflow. For example, in the call Unsafe.AddByteOffset<int>(ref ptr, a * b), the caller must ensure the intermediate value a * b does not overflow the bounds of UIntPtr.

Applies to