Marshal.ReadByte メソッド
アンマネージ ポインタから 1 バイトを読み取ります。
オーバーロードの一覧
アンマネージ ポインタから 1 バイトを読み取ります。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Shared Function ReadByte(IntPtr) As Byte
アンマネージ ポインタから、指定したオフセット (またはインデックス) の 1 バイトを読み取ります。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Shared Function ReadByte(IntPtr, Integer) As Byte
[JScript] public static function ReadByte(IntPtr, int) : Byte;
アンマネージ ポインタから 1 バイトを読み取ります。
[Visual Basic] Overloads Public Shared Function ReadByte(Object, Integer) As Byte
[JScript] public static function ReadByte(Object, int) : Byte;
使用例
[Visual Basic, C#] C スタイルのアンマネージ バイト配列と対話する 2 つの方法を比較する例を次に示します。 ReadByte メソッドを使用すると、配列の要素の値に直接アクセスできます。
[Visual Basic, C#] メモ ここでは、ReadByte のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。
Dim unmanagedArray As IntPtr = ...
Dim i As Integer
' One way to print 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
Console.WriteLine(newArray(i))
Next i
' Another way to print the 10 elements of the C-style unmanagedArray
For i = 0 To 10
Console.WriteLine(Marshal.ReadByte(unmanagedArray, i))
Next i
[C#]
IntPtr unmanagedArray = ...;
// One way to print 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++)
Console.WriteLine(newArray[i]);
// Another way to print the 10 elements of the C-style unmanagedArray
for (int i = 0; i < 10; i++)
Console.WriteLine(Marshal.ReadByte(unmanagedArray, i));
[C++, JScript] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
参照
Marshal クラス | Marshal メンバ | System.Runtime.InteropServices 名前空間