Unsafe.AsPointer<T>(T) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Important
This API is not CLS-compliant.
Converts a managed pointer into an unmanaged pointer.
public:
generic <typename T>
static void* AsPointer(T % value);
public static void* AsPointer<T> (ref T value);
[System.CLSCompliant(false)]
public static void* AsPointer<T> (ref T value);
static member AsPointer : 'T -> nativeptr<unit>
[<System.CLSCompliant(false)>]
static member AsPointer : 'T -> nativeptr<unit>
Type Parameters
- T
The elemental type of the managed pointer.
Parameters
- value
- T
The managed pointer to convert.
Returns
An unmanaged pointer corresponding to the original source pointer.
- Attributes
Remarks
Unmanaged pointers are not tracked by the .NET garbage collector. If the original managed pointer points within a GC-managed object, the caller must ensure that the source object is pinned. If the source object is not pinned and the GC relocates the object, dereferencing the unmanaged pointer could cause an access violation.