Share via


Marshal.ReadInt16 メソッド

アンマネージ メモリから 16 ビット符号付き整数を読み取ります。

オーバーロードの一覧

アンマネージ メモリから 16 ビット符号付き整数を読み取ります。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Shared Function ReadInt16(IntPtr) As Short

[C#] public static short ReadInt16(IntPtr);

[C++] public: static short ReadInt16(IntPtr);

[JScript] public static function ReadInt16(IntPtr) : Int16;

アンマネージ メモリから 16 ビット符号付き整数を読み取ります。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Shared Function ReadInt16(IntPtr, Integer) As Short

[C#] public static short ReadInt16(IntPtr, int);

[C++] public: static short ReadInt16(IntPtr, int);

[JScript] public static function ReadInt16(IntPtr, int) : Int16;

アンマネージ メモリから 16 ビット符号付き整数を読み取ります。

[Visual Basic] Overloads Public Shared Function ReadInt16(Object, Integer) As Short

[C#] public static short ReadInt16(object, int);

[C++] public: static short ReadInt16(Object, int);

[JScript] public static function ReadInt16(Object, int) : Int16;

使用例

[Visual Basic, C#] C スタイル Int16 のアンマネージ配列と対話する 2 つの方法を比較する例を次に示します。 ReadInt16 メソッドは、配列の要素の値に直接アクセスできるようにします。

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

 
Dim unmanagedArray As IntPtr = ...
Dim i As Integer
' One way to print the 10 elements of the C-style unmanagedArray
Dim newArray As Int16(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.ReadInt16(unmanagedArray, i))
Next i
   
[C#] 
IntPtr unmanagedArray = ...;
// One way to print the 10 elements of the C-style unmanagedArray
byte [] newArray = new Int16[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.ReadInt16(unmanagedArray, i));
   

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

参照

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