Marshal.WriteInt16 メソッド
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
アンマネージ メモリに 16 ビット符号付き整数を書き込みます。 アライメントされていないメモリ位置への書き込みはサポートされています。
WriteInt16(IntPtr, Char) |
文字を 16 ビット整数としてアンマネージ メモリに書き込みます。 |
WriteInt16(IntPtr, Int16) |
アンマネージ メモリに 16 ビット整数を書き込みます。 |
WriteInt16(IntPtr, Int32, Char) |
16 ビット符号付き整数値をアンマネージ メモリの指定されたオフセット位置に書き込みます。 |
WriteInt16(IntPtr, Int32, Int16) |
16 ビット符号付き整数をアンマネージ メモリの指定されたオフセット位置に書き込みます。 |
WriteInt16(Object, Int32, Char) |
古い.
16 ビット符号付き整数値をアンマネージ メモリの指定されたオフセット位置に書き込みます。 |
WriteInt16(Object, Int32, Int16) |
古い.
16 ビット符号付き整数値をアンマネージ メモリの指定されたオフセット位置に書き込みます。 |
- ソース:
- Marshal.cs
- ソース:
- Marshal.cs
- ソース:
- Marshal.cs
文字を 16 ビット整数としてアンマネージ メモリに書き込みます。
public:
static void WriteInt16(IntPtr ptr, char val);
[System.Security.SecurityCritical]
public static void WriteInt16(IntPtr ptr, char val);
public static void WriteInt16(IntPtr ptr, char val);
[<System.Security.SecurityCritical>]
static member WriteInt16 : nativeint * char -> unit
static member WriteInt16 : nativeint * char -> unit
Public Shared Sub WriteInt16 (ptr As IntPtr, val As Char)
パラメーター
- ptr
-
IntPtr
nativeint
書き込み先となるアンマネージ メモリ内のアドレス。
- val
- Char
書き込む値。
- 属性
例外
例
次の例では、 メソッドと WriteInt16 メソッドを使用してアンマネージド配列の読み取りと書き込みを行う方法をReadInt16示します。
static void ReadWriteInt16()
{
// Allocate unmanaged memory.
int elementSize = 2;
IntPtr unmanagedArray = Marshal.AllocHGlobal(10 * elementSize);
// Set the 10 elements of the C-style unmanagedArray
for (int i = 0; i < 10; i++)
{
Marshal.WriteInt16(unmanagedArray, i * elementSize, ((Int16)(i + 1)));
}
Console.WriteLine("Unmanaged memory written.");
Console.WriteLine("Reading unmanaged memory:");
// Print the 10 elements of the C-style unmanagedArray
for (int i = 0; i < 10; i++)
{
Console.WriteLine(Marshal.ReadInt16(unmanagedArray, i * elementSize));
}
Marshal.FreeHGlobal(unmanagedArray);
Console.WriteLine("Done. Press Enter to continue.");
Console.ReadLine();
}
Sub ReadWriteInt16()
' Allocate unmanaged memory.
Dim elementSize As Integer = 2
Dim unmanagedArray As IntPtr = Marshal.AllocHGlobal(10 * elementSize)
' Set the 10 elements of the C-style unmanagedArray
For i As Integer = 0 To 9
Marshal.WriteInt16(unmanagedArray, i * elementSize, CType(i + 1, Int16))
Next i
Console.WriteLine("Unmanaged memory written.")
Console.WriteLine("Reading unmanaged memory:")
' Print the 10 elements of the C-style unmanagedArray
For i As Integer = 0 To 9
Console.WriteLine(Marshal.ReadInt16(unmanagedArray, i * elementSize))
Next i
Marshal.FreeHGlobal(unmanagedArray)
Console.WriteLine("Done. Press Enter to continue.")
Console.ReadLine()
End Sub
注釈
WriteInt16 を使用すると、アンマネージ 16 ビット符号付き配列と直接やり取りできるため、アンマネージ配列全体 (を使用 Marshal.Copy) を別のマネージド配列にコピーしてから要素の値を設定する必要がなくなります。
アライメントされていないメモリ位置への書き込みはサポートされています。
こちらもご覧ください
適用対象
.NET 9 およびその他のバージョン
製品 | バージョン |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |
- ソース:
- Marshal.cs
- ソース:
- Marshal.cs
- ソース:
- Marshal.cs
アンマネージ メモリに 16 ビット整数を書き込みます。
public:
static void WriteInt16(IntPtr ptr, short val);
[System.Security.SecurityCritical]
public static void WriteInt16(IntPtr ptr, short val);
public static void WriteInt16(IntPtr ptr, short val);
[<System.Security.SecurityCritical>]
static member WriteInt16 : nativeint * int16 -> unit
static member WriteInt16 : nativeint * int16 -> unit
Public Shared Sub WriteInt16 (ptr As IntPtr, val As Short)
パラメーター
- ptr
-
IntPtr
nativeint
書き込み先となるアンマネージ メモリ内のアドレス。
- val
- Int16
書き込む値。
- 属性
例外
例
次の例では、 メソッドと WriteInt16 メソッドを使用してアンマネージド配列の読み取りと書き込みを行う方法をReadInt16示します。
static void ReadWriteInt16()
{
// Allocate unmanaged memory.
int elementSize = 2;
IntPtr unmanagedArray = Marshal.AllocHGlobal(10 * elementSize);
// Set the 10 elements of the C-style unmanagedArray
for (int i = 0; i < 10; i++)
{
Marshal.WriteInt16(unmanagedArray, i * elementSize, ((Int16)(i + 1)));
}
Console.WriteLine("Unmanaged memory written.");
Console.WriteLine("Reading unmanaged memory:");
// Print the 10 elements of the C-style unmanagedArray
for (int i = 0; i < 10; i++)
{
Console.WriteLine(Marshal.ReadInt16(unmanagedArray, i * elementSize));
}
Marshal.FreeHGlobal(unmanagedArray);
Console.WriteLine("Done. Press Enter to continue.");
Console.ReadLine();
}
Sub ReadWriteInt16()
' Allocate unmanaged memory.
Dim elementSize As Integer = 2
Dim unmanagedArray As IntPtr = Marshal.AllocHGlobal(10 * elementSize)
' Set the 10 elements of the C-style unmanagedArray
For i As Integer = 0 To 9
Marshal.WriteInt16(unmanagedArray, i * elementSize, CType(i + 1, Int16))
Next i
Console.WriteLine("Unmanaged memory written.")
Console.WriteLine("Reading unmanaged memory:")
' Print the 10 elements of the C-style unmanagedArray
For i As Integer = 0 To 9
Console.WriteLine(Marshal.ReadInt16(unmanagedArray, i * elementSize))
Next i
Marshal.FreeHGlobal(unmanagedArray)
Console.WriteLine("Done. Press Enter to continue.")
Console.ReadLine()
End Sub
注釈
WriteInt16 を使用すると、アンマネージ 16 ビット符号付き配列と直接やり取りできるため、アンマネージ配列全体 (を使用 Marshal.Copy) を別のマネージド配列にコピーしてから要素の値を設定する必要がなくなります。
アライメントされていないメモリ位置への書き込みはサポートされています。
こちらもご覧ください
適用対象
.NET 9 およびその他のバージョン
製品 | バージョン |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |
- ソース:
- Marshal.cs
- ソース:
- Marshal.cs
- ソース:
- Marshal.cs
16 ビット符号付き整数値をアンマネージ メモリの指定されたオフセット位置に書き込みます。
public:
static void WriteInt16(IntPtr ptr, int ofs, char val);
[System.Security.SecurityCritical]
public static void WriteInt16(IntPtr ptr, int ofs, char val);
public static void WriteInt16(IntPtr ptr, int ofs, char val);
[<System.Security.SecurityCritical>]
static member WriteInt16 : nativeint * int * char -> unit
static member WriteInt16 : nativeint * int * char -> unit
Public Shared Sub WriteInt16 (ptr As IntPtr, ofs As Integer, val As Char)
パラメーター
- ptr
-
IntPtr
nativeint
書き込み先となるネイティブ ヒープ内のベース アドレス。
- ofs
- Int32
書き込みの前に ptr
パラメーターに追加される追加のバイト オフセット。
- val
- Char
書き込む値。
- 属性
例外
ベース アドレス (ptr
) にオフセット バイト (ofs
) を足すと、null または無効なアドレスが生成されます。
例
次の例では、 メソッドと WriteInt16 メソッドを使用してアンマネージド配列の読み取りと書き込みを行う方法をReadInt16示します。
static void ReadWriteInt16()
{
// Allocate unmanaged memory.
int elementSize = 2;
IntPtr unmanagedArray = Marshal.AllocHGlobal(10 * elementSize);
// Set the 10 elements of the C-style unmanagedArray
for (int i = 0; i < 10; i++)
{
Marshal.WriteInt16(unmanagedArray, i * elementSize, ((Int16)(i + 1)));
}
Console.WriteLine("Unmanaged memory written.");
Console.WriteLine("Reading unmanaged memory:");
// Print the 10 elements of the C-style unmanagedArray
for (int i = 0; i < 10; i++)
{
Console.WriteLine(Marshal.ReadInt16(unmanagedArray, i * elementSize));
}
Marshal.FreeHGlobal(unmanagedArray);
Console.WriteLine("Done. Press Enter to continue.");
Console.ReadLine();
}
Sub ReadWriteInt16()
' Allocate unmanaged memory.
Dim elementSize As Integer = 2
Dim unmanagedArray As IntPtr = Marshal.AllocHGlobal(10 * elementSize)
' Set the 10 elements of the C-style unmanagedArray
For i As Integer = 0 To 9
Marshal.WriteInt16(unmanagedArray, i * elementSize, CType(i + 1, Int16))
Next i
Console.WriteLine("Unmanaged memory written.")
Console.WriteLine("Reading unmanaged memory:")
' Print the 10 elements of the C-style unmanagedArray
For i As Integer = 0 To 9
Console.WriteLine(Marshal.ReadInt16(unmanagedArray, i * elementSize))
Next i
Marshal.FreeHGlobal(unmanagedArray)
Console.WriteLine("Done. Press Enter to continue.")
Console.ReadLine()
End Sub
注釈
WriteInt16 を使用すると、アンマネージ 16 ビット符号付き配列と直接やり取りできるため、アンマネージ配列全体 (を使用 Marshal.Copy) を別のマネージド配列にコピーしてから要素の値を設定する必要がなくなります。
アライメントされていないメモリ位置への書き込みはサポートされています。
こちらもご覧ください
適用対象
.NET 9 およびその他のバージョン
製品 | バージョン |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |
- ソース:
- Marshal.cs
- ソース:
- Marshal.cs
- ソース:
- Marshal.cs
16 ビット符号付き整数をアンマネージ メモリの指定されたオフセット位置に書き込みます。
public:
static void WriteInt16(IntPtr ptr, int ofs, short val);
[System.Security.SecurityCritical]
public static void WriteInt16(IntPtr ptr, int ofs, short val);
public static void WriteInt16(IntPtr ptr, int ofs, short val);
[<System.Security.SecurityCritical>]
static member WriteInt16 : nativeint * int * int16 -> unit
static member WriteInt16 : nativeint * int * int16 -> unit
Public Shared Sub WriteInt16 (ptr As IntPtr, ofs As Integer, val As Short)
パラメーター
- ptr
-
IntPtr
nativeint
書き込み先となるアンマネージ メモリ内のベース アドレス。
- ofs
- Int32
書き込みの前に ptr
パラメーターに追加される追加のバイト オフセット。
- val
- Int16
書き込む値。
- 属性
例外
ベース アドレス (ptr
) にオフセット バイト (ofs
) を足すと、null または無効なアドレスが生成されます。
例
次の例では、 メソッドと WriteInt16 メソッドを使用してアンマネージド配列の読み取りと書き込みを行う方法をReadInt16示します。
static void ReadWriteInt16()
{
// Allocate unmanaged memory.
int elementSize = 2;
IntPtr unmanagedArray = Marshal.AllocHGlobal(10 * elementSize);
// Set the 10 elements of the C-style unmanagedArray
for (int i = 0; i < 10; i++)
{
Marshal.WriteInt16(unmanagedArray, i * elementSize, ((Int16)(i + 1)));
}
Console.WriteLine("Unmanaged memory written.");
Console.WriteLine("Reading unmanaged memory:");
// Print the 10 elements of the C-style unmanagedArray
for (int i = 0; i < 10; i++)
{
Console.WriteLine(Marshal.ReadInt16(unmanagedArray, i * elementSize));
}
Marshal.FreeHGlobal(unmanagedArray);
Console.WriteLine("Done. Press Enter to continue.");
Console.ReadLine();
}
Sub ReadWriteInt16()
' Allocate unmanaged memory.
Dim elementSize As Integer = 2
Dim unmanagedArray As IntPtr = Marshal.AllocHGlobal(10 * elementSize)
' Set the 10 elements of the C-style unmanagedArray
For i As Integer = 0 To 9
Marshal.WriteInt16(unmanagedArray, i * elementSize, CType(i + 1, Int16))
Next i
Console.WriteLine("Unmanaged memory written.")
Console.WriteLine("Reading unmanaged memory:")
' Print the 10 elements of the C-style unmanagedArray
For i As Integer = 0 To 9
Console.WriteLine(Marshal.ReadInt16(unmanagedArray, i * elementSize))
Next i
Marshal.FreeHGlobal(unmanagedArray)
Console.WriteLine("Done. Press Enter to continue.")
Console.ReadLine()
End Sub
注釈
WriteInt16 を使用すると、アンマネージ 16 ビット符号付き配列と直接やり取りできるため、アンマネージ配列全体 (を使用 Marshal.Copy) を別のマネージド配列にコピーしてから要素の値を設定する必要がなくなります。
アライメントされていないメモリ位置への書き込みはサポートされています。
こちらもご覧ください
適用対象
.NET 9 およびその他のバージョン
製品 | バージョン |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |
- ソース:
- Marshal.cs
- ソース:
- Marshal.cs
- ソース:
- Marshal.cs
注意事項
WriteInt16(Object, Int32, Char) may be unavailable in future releases.
16 ビット符号付き整数値をアンマネージ メモリの指定されたオフセット位置に書き込みます。
public:
static void WriteInt16(System::Object ^ ptr, int ofs, char val);
[System.Obsolete("WriteInt16(Object, Int32, Char) may be unavailable in future releases.")]
[System.Security.SecurityCritical]
public static void WriteInt16(object ptr, int ofs, char val);
[System.Obsolete("WriteInt16(Object, Int32, Char) may be unavailable in future releases.")]
public static void WriteInt16(object ptr, int ofs, char val);
public static void WriteInt16(object ptr, int ofs, char val);
[System.Security.SecurityCritical]
public static void WriteInt16(object ptr, int ofs, char val);
[<System.Obsolete("WriteInt16(Object, Int32, Char) may be unavailable in future releases.")>]
[<System.Security.SecurityCritical>]
static member WriteInt16 : obj * int * char -> unit
[<System.Obsolete("WriteInt16(Object, Int32, Char) may be unavailable in future releases.")>]
static member WriteInt16 : obj * int * char -> unit
static member WriteInt16 : obj * int * char -> unit
[<System.Security.SecurityCritical>]
static member WriteInt16 : obj * int * char -> unit
Public Shared Sub WriteInt16 (ptr As Object, ofs As Integer, val As Char)
パラメーター
- ptr
- Object
対象のオブジェクトのアンマネージ メモリ内のベース アドレス。
- ofs
- Int32
書き込みの前に ptr
パラメーターに追加される追加のバイト オフセット。
- val
- Char
書き込む値。
- 属性
例外
ベース アドレス (ptr
) にオフセット バイト (ofs
) を足すと、null または無効なアドレスが生成されます。
ptr
が ArrayWithOffset オブジェクトです。 このメソッドは、ArrayWithOffset パラメーターを受け入れません。
注釈
WriteInt16 を使用すると、アンマネージ 16 ビット符号付き配列と直接やり取りできるため、アンマネージ配列全体 (を使用 Marshal.Copy) を別のマネージド配列にコピーしてから要素の値を設定する必要がなくなります。
アライメントされていないメモリ位置への書き込みはサポートされています。
こちらもご覧ください
適用対象
.NET 9 およびその他のバージョン
製品 | バージョン (廃止) |
---|---|
.NET | (Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9) |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 (4.7 (package-provided), 4.7.1 (package-provided), 4.7.2 (package-provided), 4.8 (package-provided)) |
.NET Standard | 1.1, 2.0 (1.2, 1.3, 1.4, 1.5, 1.6, 2.1) |
UWP | (10.0) |
注意事項
WriteInt16(Object, Int32, Int16) may be unavailable in future releases.
16 ビット符号付き整数値をアンマネージ メモリの指定されたオフセット位置に書き込みます。
public:
static void WriteInt16(System::Object ^ ptr, int ofs, short val);
[System.Obsolete("WriteInt16(Object, Int32, Int16) may be unavailable in future releases.")]
[System.Security.SecurityCritical]
public static void WriteInt16(object ptr, int ofs, short val);
[System.Obsolete("WriteInt16(Object, Int32, Int16) may be unavailable in future releases.")]
public static void WriteInt16(object ptr, int ofs, short val);
public static void WriteInt16(object ptr, int ofs, short val);
[System.Security.SecurityCritical]
public static void WriteInt16(object ptr, int ofs, short val);
[<System.Obsolete("WriteInt16(Object, Int32, Int16) may be unavailable in future releases.")>]
[<System.Security.SecurityCritical>]
static member WriteInt16 : obj * int * int16 -> unit
[<System.Obsolete("WriteInt16(Object, Int32, Int16) may be unavailable in future releases.")>]
static member WriteInt16 : obj * int * int16 -> unit
static member WriteInt16 : obj * int * int16 -> unit
[<System.Security.SecurityCritical>]
static member WriteInt16 : obj * int * int16 -> unit
Public Shared Sub WriteInt16 (ptr As Object, ofs As Integer, val As Short)
パラメーター
- ptr
- Object
対象のオブジェクトのアンマネージ メモリ内のベース アドレス。
- ofs
- Int32
書き込みの前に ptr
パラメーターに追加される追加のバイト オフセット。
- val
- Int16
書き込む値。
- 属性
例外
ベース アドレス (ptr
) にオフセット バイト (ofs
) を足すと、null または無効なアドレスが生成されます。
ptr
が ArrayWithOffset オブジェクトです。 このメソッドは、ArrayWithOffset パラメーターを受け入れません。
注釈
WriteInt16 を使用すると、アンマネージ 16 ビット符号付き配列と直接やり取りできるため、アンマネージ配列全体 (を使用 Marshal.Copy) を別のマネージド配列にコピーしてから要素の値を設定する必要がなくなります。
アライメントされていないメモリ位置への書き込みはサポートされています。
こちらもご覧ください
適用対象
.NET 9 およびその他のバージョン
製品 | バージョン (廃止) |
---|---|
.NET | (Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9) |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 (4.7 (package-provided), 4.7.1 (package-provided), 4.7.2 (package-provided), 4.8 (package-provided)) |
.NET Standard | 1.1, 2.0 (1.2, 1.3, 1.4, 1.5, 1.6, 2.1) |
UWP | (10.0) |
.NET に関するフィードバック
.NET はオープンソース プロジェクトです。 フィードバックを提供するにはリンクを選択します。