次の方法で共有


FieldOffsetAttribute クラス

クラスまたは構造体のアンマネージ表現内にあるフィールドの物理的な位置を示します。

この型のすべてのメンバの一覧については、FieldOffsetAttribute メンバ を参照してください。

System.Object
   System.Attribute
      System.Runtime.InteropServices.FieldOffsetAttribute

<AttributeUsage(AttributeTargets.Field)>
NotInheritable Public Class FieldOffsetAttribute   Inherits Attribute
[C#]
[AttributeUsage(AttributeTargets.Field)]
public sealed class FieldOffsetAttribute : Attribute
[C++]
[AttributeUsage(AttributeTargets::Field)]
public __gc __sealed class FieldOffsetAttribute : public Attribute
[JScript]
public
   AttributeUsage(AttributeTargets.Field)
class FieldOffsetAttribute extends Attribute

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

解説

この属性は、フィールドに適用できます。

この属性は、 LayoutKind.ExplicitSystem.Runtime.InteropServices.StructLayoutAttribute がコンストラクタに渡されたときに使用され、クラスまたは構造体に適用して、そのクラスまたは構造体のアンマネージ表現内の各非静的 (Visual Basic では Shared) メンバまたは定数メンバのオフセットを指定します。この属性は、型のメンバのマネージ レイアウトには影響を与えません。

使用例

[Visual Basic, C#, C++] 明示的なレイアウトを持つクラスのメンバに FieldOffsetAttribute を適用する方法を次の例に示します。

 
<StructLayout(LayoutKind.Explicit)> _
Public Class SYSTEM_INFO
    <FieldOffset(0)> Private OemId As System.UInt64
    <FieldOffset(4)> Private PageSize As System.UInt64
    <FieldOffset(16)> Private ActiveProcessorMask As System.UInt64
    <FieldOffset(20)> Private NumberOfProcessors As System.UInt64
    <FieldOffset(24)> Private ProcessorType As System.UInt64
End Class

[C#] 
[StructLayout(LayoutKind.Explicit)]
public class SYSTEM_INFO
{
[FieldOffset(0)] public ulong OemId;
[FieldOffset(4)] public ulong PageSize;
[FieldOffset(16)] public ulong ActiveProcessorMask;
[FieldOffset(20)] public ulong NumberOfProcessors;
[FieldOffset(24)] public ulong ProcessorType;
}

[C++] 
[StructLayout(LayoutKind::Explicit)]
public __gc class SYSTEM_INFO
{
public:
[FieldOffset(0)] UInt64 OemId;
[FieldOffset(4)] UInt64 PageSize;
[FieldOffset(16)] UInt64 ActiveProcessorMask;
[FieldOffset(20)] UInt64 NumberOfProcessors;
[FieldOffset(24)] UInt64 ProcessorType;
};

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

必要条件

名前空間: System.Runtime.InteropServices

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

アセンブリ: Mscorlib (Mscorlib.dll 内)

参照

FieldOffsetAttribute メンバ | System.Runtime.InteropServices 名前空間 | StructLayoutAttribute | LayoutKind