Unsafe.Copy 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.
Overloads
Copy<T>(Void*, T) |
Copies a value of type |
Copy<T>(T, Void*) |
Copies a value of type |
Copy<T>(Void*, T)
- Source:
- Unsafe.cs
- Source:
- Unsafe.cs
- Source:
- Unsafe.cs
Important
This API is not CLS-compliant.
Copies a value of type T
to the given location.
public:
generic <typename T>
static void Copy(void* destination, T % source);
public static void Copy<T> (void* destination, ref T source);
[System.CLSCompliant(false)]
public static void Copy<T> (void* destination, ref T source);
static member Copy : nativeptr<unit> * 'T -> unit
[<System.CLSCompliant(false)>]
static member Copy : nativeptr<unit> * 'T -> unit
Type Parameters
- T
The type of value to copy.
Parameters
- destination
- Void*
The location to copy to.
- source
- T
A reference to the value to copy.
- Attributes
Remarks
Both destination
and source
are assumed to be properly aligned for pointers to data of type T
. For more information on alignment assumptions, see ECMA-335, Sec. I.12.6.2 ("Alignment").
This method is roughly equivalent to the following code.
static void Copy<T>(void* destination, ref T source)
{
T data = source; // dereference source
*(T*)destination = data;
}
Applies to
Copy<T>(T, Void*)
- Source:
- Unsafe.cs
- Source:
- Unsafe.cs
- Source:
- Unsafe.cs
Important
This API is not CLS-compliant.
Copies a value of type T
to the given location.
public:
generic <typename T>
static void Copy(T % destination, void* source);
public static void Copy<T> (ref T destination, void* source);
[System.CLSCompliant(false)]
public static void Copy<T> (ref T destination, void* source);
static member Copy : 'T * nativeptr<unit> -> unit
[<System.CLSCompliant(false)>]
static member Copy : 'T * nativeptr<unit> -> unit
Type Parameters
- T
The type of value to copy.
Parameters
- destination
- T
The location to copy to.
- source
- Void*
A pointer to the value to copy.
- Attributes
Remarks
Both destination
and source
are assumed to be properly aligned for pointers to data of type T
. For more information on alignment assumptions, see ECMA-335, Sec. I.12.6.2 ("Alignment").
This method is roughly equivalent to the following code.
static void Copy<T>(ref T destination, void* source)
{
T data = *(T*)source; // reinterpret cast source as T* and dereference
destination = data;
}