This documentation is archived and is not being maintained.

Marshal.WriteByte Method

Writes a single byte value to unmanaged memory.

Overload List

Writes a single byte value to unmanaged memory.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Sub WriteByte(IntPtr, Byte)
[C#] public static void WriteByte(IntPtr, byte);
[C++] public: static void WriteByte(IntPtr, unsigned char);
[JScript] public static function WriteByte(IntPtr, Byte);

Writes a single byte value to unmanaged memory.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Sub WriteByte(IntPtr, Integer, Byte)
[C#] public static void WriteByte(IntPtr, int, byte);
[C++] public: static void WriteByte(IntPtr, int, unsigned char);
[JScript] public static function WriteByte(IntPtr, int, Byte);

Writes a single byte value to unmanaged memory.

[Visual Basic] Overloads Public Shared Sub WriteByte(Object, Integer, Byte)
[C#] public static void WriteByte(object, int, byte);
[C++] public: static void WriteByte(Object, int, unsigned char);
[JScript] public static function WriteByte(Object, int, Byte);

Example

[Visual Basic, C#] The following example compares two ways of interacting with an unmanaged C-style byte array. The WriteByte 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 WriteByte. 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 Byte(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.WriteByte(unmanagedArray, i, i+1)
Next i
   
[C#] 
IntPtr unmanagedArray = ...;
// One way to set the 10 elements of the C-style unmanagedArray
byte [] newArray = new byte[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.WriteByte(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: