Unsafe.ByteOffset<T>(T, T) Method

Definition

Determines the byte offset from origin to target from the given managed pointers.

C#
public static IntPtr ByteOffset<T> (ref T origin, ref T target);

Type Parameters

T

The elemental type of the managed pointers.

Parameters

origin
T

The managed pointer to the origin.

target
T

The managed pointer to the target.

Returns

IntPtr

The byte offset from origin to target, that is, target - origin.

Remarks

The return value of this method is a moment-in-time result. If origin and target each reference different objects in GC-managed address space, the GC could relocate items between calls, causing the result of this method to change.

The return value is guaranteed stable if origin and target point to the same managed object.

Applies to

Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8 (package-provided), 8, 9 (package-provided), 9
.NET Framework 4.7 (package-provided), 4.7.1 (package-provided), 4.7.2 (package-provided), 4.8 (package-provided)
.NET Standard 2.0 (package-provided)