Marshal.WriteInt16 Metodo

Definizione

Scrive un valore intero con segno a 16 bit nella memoria non gestita. La scrittura in percorsi di memoria non allineati è supportata.

Overload

Nome Descrizione
WriteInt16(IntPtr, Char)

Scrive un carattere come valore intero a 16 bit nella memoria non gestita.

WriteInt16(IntPtr, Int16)

Scrive un valore intero a 16 bit nella memoria non gestita.

WriteInt16(IntPtr, Int32, Char)

Scrive un valore intero con segno a 16 bit nella memoria non gestita in corrispondenza di un offset specificato.

WriteInt16(IntPtr, Int32, Int16)

Scrive un valore intero con segno a 16 bit nella memoria non gestita in corrispondenza di un offset specificato.

WriteInt16(Object, Int32, Char)
Obsoleti.

Scrive un valore intero con segno a 16 bit nella memoria non gestita in corrispondenza di un offset specificato.

WriteInt16(Object, Int32, Int16)
Obsoleti.

Scrive un valore intero con segno a 16 bit nella memoria non gestita in corrispondenza di un offset specificato.

WriteInt16(IntPtr, Char)

Scrive un carattere come valore intero a 16 bit nella memoria non gestita.

public:
 static void WriteInt16(IntPtr ptr, char val);
[System.Security.SecurityCritical]
public static void WriteInt16(IntPtr ptr, char val);
public static void WriteInt16(IntPtr ptr, char val);
[<System.Security.SecurityCritical>]
static member WriteInt16 : nativeint * char -> unit
static member WriteInt16 : nativeint * char -> unit
Public Shared Sub WriteInt16 (ptr As IntPtr, val As Char)

Parametri

ptr
IntPtr

nativeint

Indirizzo in memoria non gestita in cui scrivere.

val
Char

Valore da scrivere.

Attributi

Eccezioni

ptr non è un formato riconosciuto.

oppure

ptr è null.

oppure

ptr non è valido.

Esempio

Nell'esempio seguente viene illustrato come leggere e scrivere in una matrice non gestita usando i ReadInt16 metodi e WriteInt16 .

static void ReadWriteInt16()
{
    // Allocate unmanaged memory. 
    int elementSize = 2;
    IntPtr unmanagedArray = Marshal.AllocHGlobal(10 * elementSize);

    // Set the 10 elements of the C-style unmanagedArray
    for (int i = 0; i < 10; i++)
    {
        Marshal.WriteInt16(unmanagedArray, i * elementSize, ((Int16)(i + 1)));
    }
    Console.WriteLine("Unmanaged memory written.");

    Console.WriteLine("Reading unmanaged memory:");
    // Print the 10 elements of the C-style unmanagedArray
    for (int i = 0; i < 10; i++)
    {
        Console.WriteLine(Marshal.ReadInt16(unmanagedArray, i * elementSize));
    }

    Marshal.FreeHGlobal(unmanagedArray);

    Console.WriteLine("Done. Press Enter to continue.");
    Console.ReadLine();
}
Sub ReadWriteInt16()
    ' Allocate unmanaged memory. 
    Dim elementSize As Integer = 2
    Dim unmanagedArray As IntPtr = Marshal.AllocHGlobal(10 * elementSize)

    ' Set the 10 elements of the C-style unmanagedArray
    For i As Integer = 0 To 9
        Marshal.WriteInt16(unmanagedArray, i * elementSize, CType(i + 1, Int16))
    Next i
    Console.WriteLine("Unmanaged memory written.")

    Console.WriteLine("Reading unmanaged memory:")
    ' Print the 10 elements of the C-style unmanagedArray
    For i As Integer = 0 To 9
        Console.WriteLine(Marshal.ReadInt16(unmanagedArray, i * elementSize))
    Next i

    Marshal.FreeHGlobal(unmanagedArray)

    Console.WriteLine("Done. Press Enter to continue.")
    Console.ReadLine()
End Sub

Commenti

WriteInt16 consente l'interazione diretta con una matrice con segno a 16 bit non gestita, eliminando i costi di copia di un'intera matrice non gestita (usando Marshal.Copy) in una matrice gestita separata prima di impostarne i valori degli elementi.

La scrittura in percorsi di memoria non allineati è supportata.

Vedi anche

Si applica a

WriteInt16(IntPtr, Int16)

Scrive un valore intero a 16 bit nella memoria non gestita.

public:
 static void WriteInt16(IntPtr ptr, short val);
[System.Security.SecurityCritical]
public static void WriteInt16(IntPtr ptr, short val);
public static void WriteInt16(IntPtr ptr, short val);
[<System.Security.SecurityCritical>]
static member WriteInt16 : nativeint * int16 -> unit
static member WriteInt16 : nativeint * int16 -> unit
Public Shared Sub WriteInt16 (ptr As IntPtr, val As Short)

Parametri

ptr
IntPtr

nativeint

Indirizzo in memoria non gestita in cui scrivere.

val
Int16

Valore da scrivere.

Attributi

Eccezioni

ptr non è un formato riconosciuto.

oppure

ptr è null.

oppure

ptr non è valido.

Esempio

Nell'esempio seguente viene illustrato come leggere e scrivere in una matrice non gestita usando i ReadInt16 metodi e WriteInt16 .

static void ReadWriteInt16()
{
    // Allocate unmanaged memory. 
    int elementSize = 2;
    IntPtr unmanagedArray = Marshal.AllocHGlobal(10 * elementSize);

    // Set the 10 elements of the C-style unmanagedArray
    for (int i = 0; i < 10; i++)
    {
        Marshal.WriteInt16(unmanagedArray, i * elementSize, ((Int16)(i + 1)));
    }
    Console.WriteLine("Unmanaged memory written.");

    Console.WriteLine("Reading unmanaged memory:");
    // Print the 10 elements of the C-style unmanagedArray
    for (int i = 0; i < 10; i++)
    {
        Console.WriteLine(Marshal.ReadInt16(unmanagedArray, i * elementSize));
    }

    Marshal.FreeHGlobal(unmanagedArray);

    Console.WriteLine("Done. Press Enter to continue.");
    Console.ReadLine();
}
Sub ReadWriteInt16()
    ' Allocate unmanaged memory. 
    Dim elementSize As Integer = 2
    Dim unmanagedArray As IntPtr = Marshal.AllocHGlobal(10 * elementSize)

    ' Set the 10 elements of the C-style unmanagedArray
    For i As Integer = 0 To 9
        Marshal.WriteInt16(unmanagedArray, i * elementSize, CType(i + 1, Int16))
    Next i
    Console.WriteLine("Unmanaged memory written.")

    Console.WriteLine("Reading unmanaged memory:")
    ' Print the 10 elements of the C-style unmanagedArray
    For i As Integer = 0 To 9
        Console.WriteLine(Marshal.ReadInt16(unmanagedArray, i * elementSize))
    Next i

    Marshal.FreeHGlobal(unmanagedArray)

    Console.WriteLine("Done. Press Enter to continue.")
    Console.ReadLine()
End Sub

Commenti

WriteInt16 consente l'interazione diretta con una matrice con segno a 16 bit non gestita, eliminando i costi di copia di un'intera matrice non gestita (usando Marshal.Copy) in una matrice gestita separata prima di impostarne i valori degli elementi.

La scrittura in percorsi di memoria non allineati è supportata.

Vedi anche

Si applica a

WriteInt16(IntPtr, Int32, Char)

Scrive un valore intero con segno a 16 bit nella memoria non gestita in corrispondenza di un offset specificato.

public:
 static void WriteInt16(IntPtr ptr, int ofs, char val);
[System.Security.SecurityCritical]
public static void WriteInt16(IntPtr ptr, int ofs, char val);
public static void WriteInt16(IntPtr ptr, int ofs, char val);
[<System.Security.SecurityCritical>]
static member WriteInt16 : nativeint * int * char -> unit
static member WriteInt16 : nativeint * int * char -> unit
Public Shared Sub WriteInt16 (ptr As IntPtr, ofs As Integer, val As Char)

Parametri

ptr
IntPtr

nativeint

Indirizzo di base nell'heap nativo in cui scrivere.

ofs
Int32

Offset di byte aggiuntivo, che viene aggiunto al parametro prima della ptr scrittura.

val
Char

Valore da scrivere.

Attributi

Eccezioni

L'indirizzo di base (ptr) più byte offset (ofs) produce un indirizzo Null o non valido.

Esempio

Nell'esempio seguente viene illustrato come leggere e scrivere in una matrice non gestita usando i ReadInt16 metodi e WriteInt16 .

static void ReadWriteInt16()
{
    // Allocate unmanaged memory. 
    int elementSize = 2;
    IntPtr unmanagedArray = Marshal.AllocHGlobal(10 * elementSize);

    // Set the 10 elements of the C-style unmanagedArray
    for (int i = 0; i < 10; i++)
    {
        Marshal.WriteInt16(unmanagedArray, i * elementSize, ((Int16)(i + 1)));
    }
    Console.WriteLine("Unmanaged memory written.");

    Console.WriteLine("Reading unmanaged memory:");
    // Print the 10 elements of the C-style unmanagedArray
    for (int i = 0; i < 10; i++)
    {
        Console.WriteLine(Marshal.ReadInt16(unmanagedArray, i * elementSize));
    }

    Marshal.FreeHGlobal(unmanagedArray);

    Console.WriteLine("Done. Press Enter to continue.");
    Console.ReadLine();
}
Sub ReadWriteInt16()
    ' Allocate unmanaged memory. 
    Dim elementSize As Integer = 2
    Dim unmanagedArray As IntPtr = Marshal.AllocHGlobal(10 * elementSize)

    ' Set the 10 elements of the C-style unmanagedArray
    For i As Integer = 0 To 9
        Marshal.WriteInt16(unmanagedArray, i * elementSize, CType(i + 1, Int16))
    Next i
    Console.WriteLine("Unmanaged memory written.")

    Console.WriteLine("Reading unmanaged memory:")
    ' Print the 10 elements of the C-style unmanagedArray
    For i As Integer = 0 To 9
        Console.WriteLine(Marshal.ReadInt16(unmanagedArray, i * elementSize))
    Next i

    Marshal.FreeHGlobal(unmanagedArray)

    Console.WriteLine("Done. Press Enter to continue.")
    Console.ReadLine()
End Sub

Commenti

WriteInt16 consente l'interazione diretta con una matrice con segno a 16 bit non gestita, eliminando i costi di copia di un'intera matrice non gestita (usando Marshal.Copy) in una matrice gestita separata prima di impostarne i valori degli elementi.

La scrittura in percorsi di memoria non allineati è supportata.

Vedi anche

Si applica a

WriteInt16(IntPtr, Int32, Int16)

Scrive un valore intero con segno a 16 bit nella memoria non gestita in corrispondenza di un offset specificato.

public:
 static void WriteInt16(IntPtr ptr, int ofs, short val);
[System.Security.SecurityCritical]
public static void WriteInt16(IntPtr ptr, int ofs, short val);
public static void WriteInt16(IntPtr ptr, int ofs, short val);
[<System.Security.SecurityCritical>]
static member WriteInt16 : nativeint * int * int16 -> unit
static member WriteInt16 : nativeint * int * int16 -> unit
Public Shared Sub WriteInt16 (ptr As IntPtr, ofs As Integer, val As Short)

Parametri

ptr
IntPtr

nativeint

Indirizzo di base nella memoria non gestita in cui scrivere.

ofs
Int32

Offset di byte aggiuntivo, che viene aggiunto al parametro prima della ptr scrittura.

val
Int16

Valore da scrivere.

Attributi

Eccezioni

L'indirizzo di base (ptr) più byte offset (ofs) produce un indirizzo Null o non valido.

Esempio

Nell'esempio seguente viene illustrato come leggere e scrivere in una matrice non gestita usando i ReadInt16 metodi e WriteInt16 .

static void ReadWriteInt16()
{
    // Allocate unmanaged memory. 
    int elementSize = 2;
    IntPtr unmanagedArray = Marshal.AllocHGlobal(10 * elementSize);

    // Set the 10 elements of the C-style unmanagedArray
    for (int i = 0; i < 10; i++)
    {
        Marshal.WriteInt16(unmanagedArray, i * elementSize, ((Int16)(i + 1)));
    }
    Console.WriteLine("Unmanaged memory written.");

    Console.WriteLine("Reading unmanaged memory:");
    // Print the 10 elements of the C-style unmanagedArray
    for (int i = 0; i < 10; i++)
    {
        Console.WriteLine(Marshal.ReadInt16(unmanagedArray, i * elementSize));
    }

    Marshal.FreeHGlobal(unmanagedArray);

    Console.WriteLine("Done. Press Enter to continue.");
    Console.ReadLine();
}
Sub ReadWriteInt16()
    ' Allocate unmanaged memory. 
    Dim elementSize As Integer = 2
    Dim unmanagedArray As IntPtr = Marshal.AllocHGlobal(10 * elementSize)

    ' Set the 10 elements of the C-style unmanagedArray
    For i As Integer = 0 To 9
        Marshal.WriteInt16(unmanagedArray, i * elementSize, CType(i + 1, Int16))
    Next i
    Console.WriteLine("Unmanaged memory written.")

    Console.WriteLine("Reading unmanaged memory:")
    ' Print the 10 elements of the C-style unmanagedArray
    For i As Integer = 0 To 9
        Console.WriteLine(Marshal.ReadInt16(unmanagedArray, i * elementSize))
    Next i

    Marshal.FreeHGlobal(unmanagedArray)

    Console.WriteLine("Done. Press Enter to continue.")
    Console.ReadLine()
End Sub

Commenti

WriteInt16 consente l'interazione diretta con una matrice con segno a 16 bit non gestita, eliminando i costi di copia di un'intera matrice non gestita (usando Marshal.Copy) in una matrice gestita separata prima di impostarne i valori degli elementi.

La scrittura in percorsi di memoria non allineati è supportata.

Vedi anche

Si applica a

WriteInt16(Object, Int32, Char)

Attenzione

WriteInt16(Object, Int32, Char) may be unavailable in future releases.

Scrive un valore intero con segno a 16 bit nella memoria non gestita in corrispondenza di un offset specificato.

public:
 static void WriteInt16(System::Object ^ ptr, int ofs, char val);
[System.Obsolete("WriteInt16(Object, Int32, Char) may be unavailable in future releases.")]
[System.Security.SecurityCritical]
public static void WriteInt16(object ptr, int ofs, char val);
public static void WriteInt16(object ptr, int ofs, char val);
[System.Security.SecurityCritical]
public static void WriteInt16(object ptr, int ofs, char val);
[System.Obsolete("WriteInt16(Object, Int32, Char) may be unavailable in future releases.")]
public static void WriteInt16(object ptr, int ofs, char val);
[<System.Obsolete("WriteInt16(Object, Int32, Char) may be unavailable in future releases.")>]
[<System.Security.SecurityCritical>]
static member WriteInt16 : obj * int * char -> unit
static member WriteInt16 : obj * int * char -> unit
[<System.Security.SecurityCritical>]
static member WriteInt16 : obj * int * char -> unit
[<System.Obsolete("WriteInt16(Object, Int32, Char) may be unavailable in future releases.")>]
static member WriteInt16 : obj * int * char -> unit
Public Shared Sub WriteInt16 (ptr As Object, ofs As Integer, val As Char)

Parametri

ptr
Object

Indirizzo di base nella memoria non gestita dell'oggetto di destinazione.

ofs
Int32

Offset di byte aggiuntivo, che viene aggiunto al parametro prima della ptr scrittura.

val
Char

Valore da scrivere.

Attributi

Eccezioni

L'indirizzo di base (ptr) più byte offset (ofs) produce un indirizzo Null o non valido.

ptr è un ArrayWithOffset oggetto . Questo metodo non accetta ArrayWithOffset parametri.

Commenti

WriteInt16 consente l'interazione diretta con una matrice con segno a 16 bit non gestita, eliminando i costi di copia di un'intera matrice non gestita (usando Marshal.Copy) in una matrice gestita separata prima di impostarne i valori degli elementi.

La scrittura in percorsi di memoria non allineati è supportata.

Vedi anche

Si applica a

WriteInt16(Object, Int32, Int16)

Attenzione

WriteInt16(Object, Int32, Int16) may be unavailable in future releases.

Scrive un valore intero con segno a 16 bit nella memoria non gestita in corrispondenza di un offset specificato.

public:
 static void WriteInt16(System::Object ^ ptr, int ofs, short val);
[System.Obsolete("WriteInt16(Object, Int32, Int16) may be unavailable in future releases.")]
[System.Security.SecurityCritical]
public static void WriteInt16(object ptr, int ofs, short val);
public static void WriteInt16(object ptr, int ofs, short val);
[System.Security.SecurityCritical]
public static void WriteInt16(object ptr, int ofs, short val);
[System.Obsolete("WriteInt16(Object, Int32, Int16) may be unavailable in future releases.")]
public static void WriteInt16(object ptr, int ofs, short val);
[<System.Obsolete("WriteInt16(Object, Int32, Int16) may be unavailable in future releases.")>]
[<System.Security.SecurityCritical>]
static member WriteInt16 : obj * int * int16 -> unit
static member WriteInt16 : obj * int * int16 -> unit
[<System.Security.SecurityCritical>]
static member WriteInt16 : obj * int * int16 -> unit
[<System.Obsolete("WriteInt16(Object, Int32, Int16) may be unavailable in future releases.")>]
static member WriteInt16 : obj * int * int16 -> unit
Public Shared Sub WriteInt16 (ptr As Object, ofs As Integer, val As Short)

Parametri

ptr
Object

Indirizzo di base nella memoria non gestita dell'oggetto di destinazione.

ofs
Int32

Offset di byte aggiuntivo, che viene aggiunto al parametro prima della ptr scrittura.

val
Int16

Valore da scrivere.

Attributi

Eccezioni

L'indirizzo di base (ptr) più byte offset (ofs) produce un indirizzo Null o non valido.

ptr è un ArrayWithOffset oggetto . Questo metodo non accetta ArrayWithOffset parametri.

Commenti

WriteInt16 consente l'interazione diretta con una matrice con segno a 16 bit non gestita, eliminando i costi di copia di un'intera matrice non gestita (usando Marshal.Copy) in una matrice gestita separata prima di impostarne i valori degli elementi.

La scrittura in percorsi di memoria non allineati è supportata.

Vedi anche

Si applica a