我在 C# 方面相对较新,我有 2 个课程。第一个类有一个公共结构,第二个类正在尝试声明该结构。我的英语不够好,但这是代码,以便您可以理解:
头等舱:
class PE
{
#region NT Headers
[StructLayout(LayoutKind.Explicit)]
public struct IMAGE_NT_HEADERS32
{
[FieldOffset(0)]
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public char[] Signature;
[FieldOffset(4)]
public IMAGE_FILE_HEADER FileHeader;
[FieldOffset(24)]
public IMAGE_OPTIONAL_HEADER32 OptionalHeader;
}
[StructLayout(LayoutKind.Explicit)]
public struct IMAGE_NT_HEADERS64
{
[FieldOffset(0)]
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public char[] Signature;
[FieldOffset(4)]
public IMAGE_FILE_HEADER FileHeader;
[FieldOffset(24)]
public IMAGE_OPTIONAL_HEADER64 OptionalHeader;
}
#endregion
}
二等:
class Main
{
struct NT_Header
{
Namespace.PE.IMAGE_NT_HEADERS32 INTSIGN =
new Namespace.PE.IMAGE_NT_HEADERS32(); //HERE IS THE ERROR!
}
}
它总是引发错误...感谢您的帮助!