Show / Hide Table of Contents

Struct Pointer<T>

CLS-compliant typed pointer for .NET languages without direct support of pointer data type.

Implements
IEquatable<Pointer<T>>
IComparable<Pointer<T>>
IStrongBox
ISupplier<nint>
IFunctional<Func<nint>>
ISupplier<nuint>
IFunctional<Func<nuint>>
IPinnable
ISpanFormattable
IFormattable
IComparisonOperators<Pointer<T>, Pointer<T>, bool>
IEqualityOperators<Pointer<T>, Pointer<T>, bool>
IAdditionOperators<Pointer<T>, int, Pointer<T>>
IAdditionOperators<Pointer<T>, long, Pointer<T>>
IAdditionOperators<Pointer<T>, nint, Pointer<T>>
IAdditionOperators<Pointer<T>, nuint, Pointer<T>>
ISubtractionOperators<Pointer<T>, int, Pointer<T>>
ISubtractionOperators<Pointer<T>, long, Pointer<T>>
ISubtractionOperators<Pointer<T>, nint, Pointer<T>>
ISubtractionOperators<Pointer<T>, nuint, Pointer<T>>
IIncrementOperators<Pointer<T>>
IDecrementOperators<Pointer<T>>
IAdditiveIdentity<Pointer<T>, nint>
IAdditiveIdentity<Pointer<T>, nuint>
Inherited Members
object.Equals(object, object)
object.GetType()
object.ReferenceEquals(object, object)
Namespace: DotNext.Runtime.InteropServices
Assembly: DotNext.Unsafe.dll
Syntax
public readonly struct Pointer<T> : IEquatable<Pointer<T>>, IComparable<Pointer<T>>, IStrongBox, ISupplier<nint>, IFunctional<Func<nint>>, ISupplier<nuint>, IFunctional<Func<nuint>>, IPinnable, ISpanFormattable, IFormattable, IComparisonOperators<Pointer<T>, Pointer<T>, bool>, IEqualityOperators<Pointer<T>, Pointer<T>, bool>, IAdditionOperators<Pointer<T>, int, Pointer<T>>, IAdditionOperators<Pointer<T>, long, Pointer<T>>, IAdditionOperators<Pointer<T>, nint, Pointer<T>>, IAdditionOperators<Pointer<T>, nuint, Pointer<T>>, ISubtractionOperators<Pointer<T>, int, Pointer<T>>, ISubtractionOperators<Pointer<T>, long, Pointer<T>>, ISubtractionOperators<Pointer<T>, nint, Pointer<T>>, ISubtractionOperators<Pointer<T>, nuint, Pointer<T>>, IIncrementOperators<Pointer<T>>, IDecrementOperators<Pointer<T>>, IAdditiveIdentity<Pointer<T>, nint>, IAdditiveIdentity<Pointer<T>, nuint> where T : unmanaged
Type Parameters
Name Description
T

The type of pointer.

Remarks

Many methods associated with the pointer are unsafe and can destabilize runtime. Moreover, pointer type doesn't provide automatic memory management. Null-pointer is the only check performed by methods.

Constructors

| Edit this page View Source

Pointer(nint)

Constructs pointer from nint value.

Declaration
public Pointer(nint ptr)
Parameters
Type Name Description
nint ptr

The pointer value.

| Edit this page View Source

Pointer(nuint)

Constructs pointer from nuint value.

Declaration
[CLSCompliant(false)]
public Pointer(nuint ptr)
Parameters
Type Name Description
nuint ptr

The pointer value.

| Edit this page View Source

Pointer(T*)

Constructs CLS-compliant pointer from non CLS-compliant pointer.

Declaration
[CLSCompliant(false)]
public Pointer(T* ptr)
Parameters
Type Name Description
T* ptr

The pointer value.

Properties

| Edit this page View Source

Address

Gets pointer address.

Declaration
public nint Address { get; }
Property Value
Type Description
nint
| Edit this page View Source

Bytes

Converts this pointer into span of bytes.

Declaration
public Span<byte> Bytes { get; }
Property Value
Type Description
Span<byte>
| Edit this page View Source

IsAligned

Determines whether this pointer is aligned to the size of T.

Declaration
public bool IsAligned { get; }
Property Value
Type Description
bool
| Edit this page View Source

IsNull

Indicates that this pointer is null.

Declaration
public bool IsNull { get; }
Property Value
Type Description
bool
| Edit this page View Source

this[nuint]

Gets or sets pointer value at the specified position in the memory.

Declaration
[CLSCompliant(false)]
public ref T this[nuint index] { get; }
Parameters
Type Name Description
nuint index

Element index.

Property Value
Type Description
T

Array element.

Remarks

This property doesn't check bounds of the array.

Exceptions
Type Condition
NullPointerException

This array is not allocated.

| Edit this page View Source

Null

Represents zero pointer.

Declaration
public static Pointer<T> Null { get; }
Property Value
Type Description
Pointer<T>
| Edit this page View Source

Value

Gets the value stored in the memory identified by this pointer.

Declaration
public ref T Value { get; }
Property Value
Type Description
T

The reference to the memory location.

Exceptions
Type Condition
NullPointerException

The pointer is 0.

Methods

| Edit this page View Source

AsStream(long, FileAccess)

Returns representation of the memory identified by this pointer in the form of the stream.

Declaration
public Stream AsStream(long count, FileAccess access = FileAccess.ReadWrite)
Parameters
Type Name Description
long count

The number of elements of type T referenced by this memory.

FileAccess access

The type of the access supported by the returned stream.

Returns
Type Description
Stream

The stream representing the memory identified by this pointer.

Remarks

This method returns Stream compatible over the memory identified by this pointer. No copying is performed.

Exceptions
Type Condition
ArgumentOutOfRangeException

count is less than 0.

| Edit this page View Source

As<TOther>()

Reinterprets pointer type.

Declaration
public Pointer<TOther> As<TOther>() where TOther : unmanaged
Returns
Type Description
Pointer<TOther>

Reinterpreted pointer type.

Type Parameters
Name Description
TOther

A new pointer type.

Exceptions
Type Condition
GenericArgumentException<T>

Type TOther should be the same size or less than type T.

| Edit this page View Source

BitwiseCompare(Pointer<T>, nuint)

Bitwise comparison of two memory blocks.

Declaration
[CLSCompliant(false)]
public int BitwiseCompare(Pointer<T> other, nuint count)
Parameters
Type Name Description
Pointer<T> other

The pointer identifies block of memory to be compared.

nuint count

The number of elements of type T referenced by both pointers.

Returns
Type Description
int

Comparison result which has the semantics as return type of CompareTo(object).

| Edit this page View Source

Clear()

Sets value at the address represented by this pointer to the default value of T.

Declaration
public void Clear()
Exceptions
Type Condition
NullPointerException

This pointer is equal to zero.

| Edit this page View Source

Clear(nuint)

Fill memory with zero bytes.

Declaration
[CLSCompliant(false)]
public void Clear(nuint count)
Parameters
Type Name Description
nuint count

Number of elements in the unmanaged array.

Exceptions
Type Condition
NullPointerException

This pointer is equal to zero.

| Edit this page View Source

CopyTo(Pointer<T>, nuint)

Copies block of memory from the source address to the destination address.

Declaration
[CLSCompliant(false)]
public void CopyTo(Pointer<T> destination, nuint count)
Parameters
Type Name Description
Pointer<T> destination

Destination address.

nuint count

The number of elements to be copied.

Exceptions
Type Condition
NullPointerException

This pointer is equal to zero.

ArgumentNullException

Destination pointer is zero.

| Edit this page View Source

CopyTo(Span<T>)

Copies a block of memory identifier by this pointer to the specified location.

Declaration
public void CopyTo(Span<T> destination)
Parameters
Type Name Description
Span<T> destination

The destination memory block.

Exceptions
Type Condition
ArgumentNullException

Destination pointer is zero.

| Edit this page View Source

Equals(object?)

Indicates that this pointer represents the same memory location as other pointer.

Declaration
public override bool Equals(object? other)
Parameters
Type Name Description
object other

The object of type Pointer<T> to be compared.

Returns
Type Description
bool

true, if this pointer represents the same memory location as other pointer; otherwise, false.

Overrides
ValueType.Equals(object)
| Edit this page View Source

Equals(T, IEqualityComparer<T>)

Determines whether the value stored in the memory identified by this pointer is equal to the given value.

Declaration
public bool Equals(T other, IEqualityComparer<T> comparer)
Parameters
Type Name Description
T other

The value to be compared.

IEqualityComparer<T> comparer

The object implementing comparison algorithm.

Returns
Type Description
bool

true, if the value stored in the memory identified by this pointer is equal to the given value; otherwise, false.

| Edit this page View Source

Equals<TOther>(Pointer<TOther>)

Indicates that this pointer represents the same memory location as other pointer.

Declaration
public bool Equals<TOther>(Pointer<TOther> other) where TOther : unmanaged
Parameters
Type Name Description
Pointer<TOther> other

The pointer to be compared.

Returns
Type Description
bool

true, if this pointer represents the same memory location as other pointer; otherwise, false.

Type Parameters
Name Description
TOther

The type of the another pointer.

| Edit this page View Source

Fill(T, nuint)

Fills the elements of the array with a specified value.

Declaration
[CLSCompliant(false)]
public void Fill(T value, nuint count)
Parameters
Type Name Description
T value

The value to assign to each element of the array.

nuint count

The length of the array.

Exceptions
Type Condition
NullPointerException

This pointer is zero.

| Edit this page View Source

GetBoxedPointer()

Gets boxed pointer.

Declaration
[CLSCompliant(false)]
public object GetBoxedPointer()
Returns
Type Description
object

The boxed pointer.

See Also
Pointer
| Edit this page View Source

GetEnumerator(nuint)

Gets enumerator over raw memory.

Declaration
[CLSCompliant(false)]
public Pointer<T>.Enumerator GetEnumerator(nuint length)
Parameters
Type Name Description
nuint length

A number of elements to iterate.

Returns
Type Description
Pointer<T>.Enumerator

Iterator object.

| Edit this page View Source

GetHashCode()

Computes hash code of the pointer itself (i.e. address), not of the memory content.

Declaration
public override int GetHashCode()
Returns
Type Description
int

The hash code of this pointer.

Overrides
ValueType.GetHashCode()
| Edit this page View Source

GetHashCode(IEqualityComparer<T>)

Computes hash code of the value stored in the memory identified by this pointer.

Declaration
public int GetHashCode(IEqualityComparer<T> comparer)
Parameters
Type Name Description
IEqualityComparer<T> comparer

The object implementing custom hash function.

Returns
Type Description
int

The hash code of the value stored in the memory identified by this pointer.

| Edit this page View Source

GetUnaligned()

Dereferences this pointer, assuming that this pointer is unaligned.

Declaration
public T GetUnaligned()
Returns
Type Description
T

The value stored in the memory.

Exceptions
Type Condition
NullPointerException

The pointer is zero.

| Edit this page View Source

GetUnaligned(nuint)

Gets the value stored in the memory at the specified position, assuming that this pointer is unaligned.

Declaration
[CLSCompliant(false)]
public T GetUnaligned(nuint index)
Parameters
Type Name Description
nuint index

The index of the element.

Returns
Type Description
T

The value stored in the memory at the specified position.

Exceptions
Type Condition
NullPointerException

The pointer is zero.

| Edit this page View Source

Pin(int)

Pins a block of memory.

Declaration
public MemoryHandle Pin(int elementIndex)
Parameters
Type Name Description
int elementIndex

The offset to the element within the memory buffer to which the returned MemoryHandle points.

Returns
Type Description
MemoryHandle

A handle to the block of memory.

| Edit this page View Source

ReadFrom(Stream, long)

Copies bytes from the given stream to the memory location identified by this pointer.

Declaration
public long ReadFrom(Stream source, long count)
Parameters
Type Name Description
Stream source

The source stream.

long count

The number of elements of type T to be copied.

Returns
Type Description
long

The actual number of copied elements.

Exceptions
Type Condition
NullPointerException

This pointer is zero.

ArgumentException

The stream is not readable.

ArgumentOutOfRangeException

count is less than zero.

| Edit this page View Source

ReadFromAsync(Stream, long, CancellationToken)

Copies bytes from the given stream to the memory location identified by this pointer asynchronously.

Declaration
public ValueTask<long> ReadFromAsync(Stream source, long count, CancellationToken token = default)
Parameters
Type Name Description
Stream source

The source stream.

long count

The number of elements of type T to be copied.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask<long>

The actual number of copied elements.

Exceptions
Type Condition
NullPointerException

This pointer is zero.

ArgumentException

The stream is not readable.

ArgumentOutOfRangeException

count is less than zero.

OperationCanceledException

The operation has been canceled.

| Edit this page View Source

SetUnaligned(T)

Sets the value stored in the memory identified by this pointer, assuming that this pointer is unaligned.

Declaration
public void SetUnaligned(T value)
Parameters
Type Name Description
T value

The value to be stored in the memory.

Exceptions
Type Condition
NullPointerException

The pointer is 0.

| Edit this page View Source

SetUnaligned(T, nuint)

Sets the value at the specified position in the memory, assuming that this pointer is unaligned.

Declaration
[CLSCompliant(false)]
public void SetUnaligned(T value, nuint index)
Parameters
Type Name Description
T value

The value to be stored in the memory.

nuint index

The index of the element to modify.

Exceptions
Type Condition
NullPointerException

The pointer is 0.

| Edit this page View Source

Swap(Pointer<T>)

Swaps values between this memory location and the given memory location.

Declaration
public void Swap(Pointer<T> other)
Parameters
Type Name Description
Pointer<T> other

The other memory location.

Exceptions
Type Condition
NullPointerException

This pointer is zero.

ArgumentNullException

other pointer is zero.

| Edit this page View Source

ToArray(int)

Copies the block of memory referenced by this pointer into managed heap as a pinned array.

Declaration
public T[] ToArray(int length)
Parameters
Type Name Description
int length

The length of the memory block to be copied.

Returns
Type Description
T[]

The array containing elements from the memory block referenced by this pointer.

Exceptions
Type Condition
ArgumentOutOfRangeException

length is negative.

| Edit this page View Source

ToByteArray(int)

Copies the block of memory referenced by this pointer into managed heap as array of bytes.

Declaration
public byte[] ToByteArray(int length)
Parameters
Type Name Description
int length

Number of elements to copy.

Returns
Type Description
byte[]

A copy of memory block in the form of byte array.

Exceptions
Type Condition
ArgumentOutOfRangeException

length is negative.

| Edit this page View Source

ToMemoryOwner(int)

Converts this pointer the memory owner.

Declaration
public IMemoryOwner<T> ToMemoryOwner(int length)
Parameters
Type Name Description
int length

The number of elements in the memory.

Returns
Type Description
IMemoryOwner<T>

The instance of memory owner.

| Edit this page View Source

ToSpan(int)

Converts this pointer into Span<T>.

Declaration
public Span<T> ToSpan(int length)
Parameters
Type Name Description
int length

The number of elements located in the unmanaged memory identified by this pointer.

Returns
Type Description
Span<T>

Span<T> representing elements in the unmanaged memory.

| Edit this page View Source

ToString()

Returns hexadecimal address represented by this pointer.

Declaration
public override string ToString()
Returns
Type Description
string

The hexadecimal value of this pointer.

Overrides
ValueType.ToString()
| Edit this page View Source

WriteTo(Stream, long)

Copies bytes from the memory location identified by this pointer to the stream.

Declaration
[CLSCompliant(false)]
public void WriteTo(Stream destination, long count)
Parameters
Type Name Description
Stream destination

The destination stream.

long count

The number of elements of type T to be copied.

Exceptions
Type Condition
NullPointerException

This pointer is equal to zero.

ArgumentException

The stream is not writable.

ArgumentOutOfRangeException

count is less than zero.

| Edit this page View Source

WriteToAsync(Stream, long, CancellationToken)

Copies bytes from the memory location identified by this pointer to the stream asynchronously.

Declaration
public ValueTask WriteToAsync(Stream destination, long count, CancellationToken token = default)
Parameters
Type Name Description
Stream destination

The destination stream.

long count

The number of elements of type T to be copied.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask

The task instance representing asynchronous state of the copying process.

Exceptions
Type Condition
NullPointerException

This pointer is equal to zero.

ArgumentOutOfRangeException

count is less than zero.

ArgumentException

The stream is not writable.

OperationCanceledException

The operation has been canceled.

Operators

| Edit this page View Source

operator +(Pointer<T>, int)

Adds an offset to the value of a pointer.

Declaration
public static Pointer<T> operator +(Pointer<T> pointer, int offset)
Parameters
Type Name Description
Pointer<T> pointer

The pointer to add the offset to.

int offset

The offset to add.

Returns
Type Description
Pointer<T>

A new pointer that reflects the addition of offset to pointer.

Remarks

The offset specifies number of elements of type T, not bytes.

| Edit this page View Source

operator +(Pointer<T>, long)

Adds an offset to the value of a pointer.

Declaration
public static Pointer<T> operator +(Pointer<T> pointer, long offset)
Parameters
Type Name Description
Pointer<T> pointer

The pointer to add the offset to.

long offset

The offset to add.

Returns
Type Description
Pointer<T>

A new pointer that reflects the addition of offset to pointer.

Remarks

The offset specifies number of elements of type T, not bytes.

| Edit this page View Source

operator +(Pointer<T>, nint)

Adds an offset to the value of a pointer.

Declaration
public static Pointer<T> operator +(Pointer<T> pointer, nint offset)
Parameters
Type Name Description
Pointer<T> pointer

The pointer to add the offset to.

nint offset

The offset to add.

Returns
Type Description
Pointer<T>

A new pointer that reflects the addition of offset to pointer.

Remarks

The offset specifies number of elements of type T, not bytes.

| Edit this page View Source

operator +(Pointer<T>, nuint)

Adds an offset to the value of a pointer.

Declaration
[CLSCompliant(false)]
public static Pointer<T> operator +(Pointer<T> pointer, nuint offset)
Parameters
Type Name Description
Pointer<T> pointer

The pointer to add the offset to.

nuint offset

The offset to add.

Returns
Type Description
Pointer<T>

A new pointer that reflects the addition of offset to pointer.

Remarks

The offset specifies number of elements of type T, not bytes.

| Edit this page View Source

operator checked +(Pointer<T>, int)

Adds an offset to the value of a pointer.

Declaration
public static Pointer<T> operator checked +(Pointer<T> pointer, int offset)
Parameters
Type Name Description
Pointer<T> pointer

The pointer to add the offset to.

int offset

The offset to add.

Returns
Type Description
Pointer<T>

A new pointer that reflects the addition of offset to pointer.

Remarks

The offset specifies number of elements of type T, not bytes.

| Edit this page View Source

operator checked +(Pointer<T>, long)

Adds an offset to the value of a pointer.

Declaration
public static Pointer<T> operator checked +(Pointer<T> pointer, long offset)
Parameters
Type Name Description
Pointer<T> pointer

The pointer to add the offset to.

long offset

The offset to add.

Returns
Type Description
Pointer<T>

A new pointer that reflects the addition of offset to pointer.

Remarks

The offset specifies number of elements of type T, not bytes.

| Edit this page View Source

operator checked +(Pointer<T>, nint)

Adds an offset to the value of a pointer.

Declaration
public static Pointer<T> operator checked +(Pointer<T> pointer, nint offset)
Parameters
Type Name Description
Pointer<T> pointer

The pointer to add the offset to.

nint offset

The offset to add.

Returns
Type Description
Pointer<T>

A new pointer that reflects the addition of offset to pointer.

Remarks

The offset specifies number of elements of type T, not bytes.

| Edit this page View Source

operator checked --(Pointer<T>)

Decrements this pointer by 1 element of type T.

Declaration
public static Pointer<T> operator checked --(Pointer<T> pointer)
Parameters
Type Name Description
Pointer<T> pointer

The pointer to subtract the offset from.

Returns
Type Description
Pointer<T>

A new pointer that reflects the subtraction of offset from pointer.

| Edit this page View Source

operator checked ++(Pointer<T>)

Increments this pointer by 1 element of type T.

Declaration
public static Pointer<T> operator checked ++(Pointer<T> pointer)
Parameters
Type Name Description
Pointer<T> pointer

The pointer to add the offset to.

Returns
Type Description
Pointer<T>

A new pointer that reflects the addition of offset to pointer.

| Edit this page View Source

operator checked -(Pointer<T>, int)

Subtracts an offset from the value of a pointer.

Declaration
public static Pointer<T> operator checked -(Pointer<T> pointer, int offset)
Parameters
Type Name Description
Pointer<T> pointer

The pointer to subtract the offset from.

int offset

The offset to subtract.

Returns
Type Description
Pointer<T>

A new pointer that reflects the subtraction of offset from pointer.

Remarks

The offset specifies number of elements of type T, not bytes.

| Edit this page View Source

operator checked -(Pointer<T>, long)

Subtracts an offset from the value of a pointer.

Declaration
public static Pointer<T> operator checked -(Pointer<T> pointer, long offset)
Parameters
Type Name Description
Pointer<T> pointer

The pointer to subtract the offset from.

long offset

The offset to subtract.

Returns
Type Description
Pointer<T>

A new pointer that reflects the subtraction of offset from pointer.

Remarks

The offset specifies number of elements of type T, not bytes.

| Edit this page View Source

operator checked -(Pointer<T>, nint)

Subtracts an offset from the value of a pointer.

Declaration
public static Pointer<T> operator checked -(Pointer<T> pointer, nint offset)
Parameters
Type Name Description
Pointer<T> pointer

The pointer to subtract the offset from.

nint offset

The offset to subtract.

Returns
Type Description
Pointer<T>

A new pointer that reflects the subtraction of offset from pointer.

Remarks

The offset specifies number of elements of type T, not bytes.

| Edit this page View Source

operator checked -(Pointer<T>, nuint)

Subtracts an offset from the value of a pointer.

Declaration
[CLSCompliant(false)]
public static Pointer<T> operator checked -(Pointer<T> pointer, nuint offset)
Parameters
Type Name Description
Pointer<T> pointer

The pointer to subtract the offset from.

nuint offset

The offset to subtract.

Returns
Type Description
Pointer<T>

A new pointer that reflects the subtraction of offset from pointer.

Remarks

The offset specifies number of elements of type T, not bytes.

| Edit this page View Source

operator --(Pointer<T>)

Decrements this pointer by 1 element of type T.

Declaration
public static Pointer<T> operator --(Pointer<T> pointer)
Parameters
Type Name Description
Pointer<T> pointer

The pointer to subtract the offset from.

Returns
Type Description
Pointer<T>

A new pointer that reflects the subtraction of offset from pointer.

| Edit this page View Source

operator ==(Pointer<T>, Pointer<T>)

Indicates that the first pointer represents the same memory location as the second pointer.

Declaration
public static bool operator ==(Pointer<T> first, Pointer<T> second)
Parameters
Type Name Description
Pointer<T> first

The first pointer to be compared.

Pointer<T> second

The second pointer to be compared.

Returns
Type Description
bool

true, if the first pointer represents the same memory location as the second pointer; otherwise, false.

| Edit this page View Source

explicit operator Pointer<T>(in MemoryHandle)

Obtains pointer to the memory represented by given memory handle.

Declaration
public static explicit operator Pointer<T>(in MemoryHandle handle)
Parameters
Type Name Description
MemoryHandle handle

The memory handle.

Returns
Type Description
Pointer<T>
| Edit this page View Source

operator false(Pointer<T>)

Checks whether this pointer is zero.

Declaration
public static bool operator false(Pointer<T> ptr)
Parameters
Type Name Description
Pointer<T> ptr

The pointer to check.

Returns
Type Description
bool

true, if this pointer is zero; otherwise, false.

| Edit this page View Source

operator >(Pointer<T>, Pointer<T>)

Determines whether the address of the first pointer is greater than the address of the second pointer.

Declaration
public static bool operator >(Pointer<T> first, Pointer<T> second)
Parameters
Type Name Description
Pointer<T> first

The first pointer to compare.

Pointer<T> second

The second pointer to compare.

Returns
Type Description
bool

true if first is greater than second; otherwise, false.

| Edit this page View Source

operator >=(Pointer<T>, Pointer<T>)

Determines whether the address of the first pointer is greater than or equal to the address of the second pointer.

Declaration
public static bool operator >=(Pointer<T> first, Pointer<T> second)
Parameters
Type Name Description
Pointer<T> first

The first pointer to compare.

Pointer<T> second

The second pointer to compare.

Returns
Type Description
bool

true if first is greater than or equal to second; otherwise, false.

| Edit this page View Source

implicit operator nint(Pointer<T>)

Obtains pointer value (address) as nint.

Declaration
public static implicit operator nint(Pointer<T> ptr)
Parameters
Type Name Description
Pointer<T> ptr

The pointer to be converted.

Returns
Type Description
nint
| Edit this page View Source

implicit operator nuint(Pointer<T>)

Obtains pointer value (address) as nuint.

Declaration
[CLSCompliant(false)]
public static implicit operator nuint(Pointer<T> ptr)
Parameters
Type Name Description
Pointer<T> ptr

The pointer to be converted.

Returns
Type Description
nuint
| Edit this page View Source

implicit operator T*(Pointer<T>)

Converts CLS-compliant pointer into its non CLS-compliant representation.

Declaration
[CLSCompliant(false)]
public static implicit operator T*(Pointer<T> ptr)
Parameters
Type Name Description
Pointer<T> ptr

The pointer value.

Returns
Type Description
T*
| Edit this page View Source

implicit operator Pointer<T>(T*)

Converts non CLS-compliant pointer into its CLS-compliant representation.

Declaration
[CLSCompliant(false)]
public static implicit operator Pointer<T>(T* value)
Parameters
Type Name Description
T* value

The pointer value.

Returns
Type Description
Pointer<T>
| Edit this page View Source

operator ++(Pointer<T>)

Increments this pointer by 1 element of type T.

Declaration
public static Pointer<T> operator ++(Pointer<T> pointer)
Parameters
Type Name Description
Pointer<T> pointer

The pointer to add the offset to.

Returns
Type Description
Pointer<T>

A new pointer that reflects the addition of offset to pointer.

| Edit this page View Source

operator !=(Pointer<T>, Pointer<T>)

Indicates that the first pointer represents the different memory location as the second pointer.

Declaration
public static bool operator !=(Pointer<T> first, Pointer<T> second)
Parameters
Type Name Description
Pointer<T> first

The first pointer to be compared.

Pointer<T> second

The second pointer to be compared.

Returns
Type Description
bool

true, if the first pointer represents the different memory location as the second pointer; otherwise, false.

| Edit this page View Source

operator <(Pointer<T>, Pointer<T>)

Determines whether the address of the first pointer is less than the address of the second pointer.

Declaration
public static bool operator <(Pointer<T> first, Pointer<T> second)
Parameters
Type Name Description
Pointer<T> first

The first pointer to compare.

Pointer<T> second

The second pointer to compare.

Returns
Type Description
bool

true if first is less than second; otherwise, false.

| Edit this page View Source

operator <=(Pointer<T>, Pointer<T>)

Determines whether the address of the first pointer is less than or equal to the address of the second pointer.

Declaration
public static bool operator <=(Pointer<T> first, Pointer<T> second)
Parameters
Type Name Description
Pointer<T> first

The first pointer to compare.

Pointer<T> second

The second pointer to compare.

Returns
Type Description
bool

true if first is less than or equal to second; otherwise, false.

| Edit this page View Source

operator -(Pointer<T>, int)

Subtracts an offset from the value of a pointer.

Declaration
public static Pointer<T> operator -(Pointer<T> pointer, int offset)
Parameters
Type Name Description
Pointer<T> pointer

The pointer to subtract the offset from.

int offset

The offset to subtract.

Returns
Type Description
Pointer<T>

A new pointer that reflects the subtraction of offset from pointer.

Remarks

The offset specifies number of elements of type T, not bytes.

| Edit this page View Source

operator -(Pointer<T>, long)

Subtracts an offset from the value of a pointer.

Declaration
public static Pointer<T> operator -(Pointer<T> pointer, long offset)
Parameters
Type Name Description
Pointer<T> pointer

The pointer to subtract the offset from.

long offset

The offset to subtract.

Returns
Type Description
Pointer<T>

A new pointer that reflects the subtraction of offset from pointer.

Remarks

The offset specifies number of elements of type T, not bytes.

| Edit this page View Source

operator -(Pointer<T>, nint)

Subtracts an offset from the value of a pointer.

Declaration
public static Pointer<T> operator -(Pointer<T> pointer, nint offset)
Parameters
Type Name Description
Pointer<T> pointer

The pointer to subtract the offset from.

nint offset

The offset to subtract.

Returns
Type Description
Pointer<T>

A new pointer that reflects the subtraction of offset from pointer.

Remarks

The offset specifies number of elements of type T, not bytes.

| Edit this page View Source

operator -(Pointer<T>, nuint)

Subtracts an offset from the value of a pointer.

Declaration
[CLSCompliant(false)]
public static Pointer<T> operator -(Pointer<T> pointer, nuint offset)
Parameters
Type Name Description
Pointer<T> pointer

The pointer to subtract the offset from.

nuint offset

The offset to subtract.

Returns
Type Description
Pointer<T>

A new pointer that reflects the subtraction of offset from pointer.

Remarks

The offset specifies number of elements of type T, not bytes.

| Edit this page View Source

operator true(Pointer<T>)

Checks whether this pointer is not zero.

Declaration
public static bool operator true(Pointer<T> ptr)
Parameters
Type Name Description
Pointer<T> ptr

The pointer to check.

Returns
Type Description
bool

true, if this pointer is not zero; otherwise, false.

Implements

IEquatable<T>
IComparable<T>
IStrongBox
ISupplier<TResult>
IFunctional<TDelegate>
ISupplier<TResult>
IFunctional<TDelegate>
IPinnable
ISpanFormattable
IFormattable
IComparisonOperators<TSelf, TOther, TResult>
IEqualityOperators<TSelf, TOther, TResult>
IAdditionOperators<TSelf, TOther, TResult>
IAdditionOperators<TSelf, TOther, TResult>
IAdditionOperators<TSelf, TOther, TResult>
IAdditionOperators<TSelf, TOther, TResult>
ISubtractionOperators<TSelf, TOther, TResult>
ISubtractionOperators<TSelf, TOther, TResult>
ISubtractionOperators<TSelf, TOther, TResult>
ISubtractionOperators<TSelf, TOther, TResult>
IIncrementOperators<TSelf>
IDecrementOperators<TSelf>
IAdditiveIdentity<TSelf, TResult>
IAdditiveIdentity<TSelf, TResult>

Extension Methods

BasicExtensions.Disclosed<T>(T)
BasicExtensions.Enclosed<T>(T)
BasicExtensions.IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
BasicExtensions.IsOneOf<T>(T, ReadOnlySpan<T>)
Collection.ToAsyncEnumerator<TEnumerator, T>(TEnumerator, CancellationToken)
Collection.ToClassicEnumerator<TEnumerator, T>(TEnumerator)
Enumerator.Skip<TEnumerator, T>(ref TEnumerator, int)
ExpressionBuilder.Const<T>(T)
  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾