Share via


Marshal.WriteByte メソッド

1 バイト値をアンマネージ メモリに書き込みます。

オーバーロードの一覧

1 バイト値をアンマネージ メモリに書き込みます。

.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);

1 バイト値をアンマネージ メモリに書き込みます。

.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);

1 バイト値をアンマネージ メモリに書き込みます。

[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);

使用例

[Visual Basic, C#] C スタイルのアンマネージ バイト配列と対話する 2 つの方法を比較する例を次に示します。 WriteByte メソッドを使用すると、配列の要素の値に直接アクセスでき、その 10 の要素に値 1 ~ 10 を設定します。

[Visual Basic, C#] メモ   ここでは、WriteByte のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。

 
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] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

参照

Marshal クラス | Marshal メンバ | System.Runtime.InteropServices 名前空間