Bewerken

Delen via


Unsafe.Copy Method

Definition

Overloads

Copy<T>(Void*, T)

Copies a value of type T to the given location.

Copy<T>(T, Void*)

Copies a value of type T to the given location.

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;
}

Applies to