This documentation is archived and is not being maintained.

Marshal.WriteInt16 Method

Writes a 16-bit signed integer value to unmanaged memory.

Overload List

Writes a 16-bit signed integer value to unmanaged memory.

[Visual Basic] Overloads Public Shared Sub WriteInt16(IntPtr, Char)
[C#] public static void WriteInt16(IntPtr, char);
[C++] public: static void WriteInt16(IntPtr, __wchar_t);
[JScript] public static function WriteInt16(IntPtr, Char);

Writes a 16-bit integer value to unmanaged memory.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Sub WriteInt16(IntPtr, Short)
[C#] public static void WriteInt16(IntPtr, short);
[C++] public: static void WriteInt16(IntPtr, short);
[JScript] public static function WriteInt16(IntPtr, Int16);

Writes a 16-bit signed integer value to unmanaged memory.

[Visual Basic] Overloads Public Shared Sub WriteInt16(IntPtr, Integer, Char)
[C#] public static void WriteInt16(IntPtr, int, char);
[C++] public: static void WriteInt16(IntPtr, int, __wchar_t);
[JScript] public static function WriteInt16(IntPtr, int, Char);

Writes a 16-bit signed integer value into unmanaged memory.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Sub WriteInt16(IntPtr, Integer, Short)
[C#] public static void WriteInt16(IntPtr, int, short);
[C++] public: static void WriteInt16(IntPtr, int, short);
[JScript] public static function WriteInt16(IntPtr, int, Int16);

Writes a 16-bit signed integer value to unmanaged memory.

[Visual Basic] Overloads Public Shared Sub WriteInt16(Object, Integer, Char)
[C#] public static void WriteInt16(object, int, char);
[C++] public: static void WriteInt16(Object, int, __wchar_t);
[JScript] public static function WriteInt16(Object, int, Char);

Writes a 16-bit signed integer value to unmanaged memory.

[Visual Basic] Overloads Public Shared Sub WriteInt16(Object, Integer, Short)
[C#] public static void WriteInt16(object, int, short);
[C++] public: static void WriteInt16(Object, int, short);
[JScript] public static function WriteInt16(Object, int, Int16);

Example

[Visual Basic, C#] The following example compares two ways of interacting with an unmanaged C-style Int16 array. The WriteInt16 method provides direct access to the element values of the array, setting its ten elements to the values 1 through 10.

[Visual Basic, C#] Note   This example shows how to use one of the overloaded versions of WriteInt16. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Dim unmanagedArray As IntPtr = ...
Dim i As Integer
' One way to set the 10 elements of the C-style unmanagedArray
Dim newArray As Short(9)
Marshal.Copy(unmanagedArray, newArray, 0, 10)
For i = 0 To newArray.Length
  newArray(i) = i+1
Next i
Marshal.Copy(newArray, 0, unmanagedArray, 10)
' Another way to set the 10 elements of the C-style unmanagedArray
For i = 0 To 10
  Marshal.WriteInt16(unmanagedArray, i, i+1)
Next i
   
[C#] 
IntPtr unmanagedArray = ...;
// One way to set the 10 elements of the C-style unmanagedArray
byte [] newArray = new short[10];
Marshal.Copy(unmanagedArray, newArray, 0, 10);
for (int i = 0; i < newArray.Length; i++)
  newArray[i] = i+1;
Marshal.Copy(newArray, 0, unmanagedArray, 10);
// Another way to set the 10 elements of the C-style unmanagedArray
for (int i = 0; i < 10; i++)
  Marshal.WriteInt16(unmanagedArray, i, i+1);
   

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

Marshal Class | Marshal Members | System.Runtime.InteropServices Namespace

Show: