询问者
结构体数组嵌套结构体数组

问题
-
[StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
public struct BleGattCharacteristicSate_T
{
public UInt16 Handle_s;
public UInt16 Handle_e;
public Byte Properties;
public UInt16 Uuid;
public UInt16 ConfigHandle;
public UInt16 ConfigUuid;
}
[StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
public struct BleGattServeiceState_T
{
public UInt16 Handle_S;
public UInt16 Handle_E;
public UInt16 Uuid;
public Byte CharacteristicLen;
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = 20)]
public BleGattCharacteristicSate_T[] Characteristic;
}
public static BleGattServeiceState_T[] BleGattServeice = new BleGattServeiceState_T[20];上面是我想申明的结构体,但是在 public BleGattCharacteristicSate_T[] Characteristic;申明中,并没有得到new,使得元素Characteristic不能使用,
请问正确的申明方式?
谢谢!
全部回复
-
Hi,
感谢你在MSDN论坛发帖。
如果你想声明下面这种结构体:
typedef struct _MYARRAYSTRUCT { bool flag; int vals[ 3 ]; } MYARRAYSTRUCT;
可能需要这样写:
[StructLayout(LayoutKind.Sequential)] public struct MyArrayStruct { public bool flag; [MarshalAs(UnmanagedType.ByValArray, SizeConst=3)] public int[] vals; }
我也找到相关的文档,关于声明结构体的。希望对你有所帮助.
https://msdn.microsoft.com/ZH-CN/library/eshywdt7%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396https://msdn.microsoft.com/ZH-CN/library/hk9wyw21(v=vs.110).aspx
Best Regards,
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
- 已建议为答案 Hart WangModerator 2017年3月24日 7:31
-
谢谢回复
- 已建议为答案 Hart WangModerator 2017年4月3日 8:23
- 取消建议作为答案 Hart WangModerator 2017年5月18日 6:51
-
如果你的问题解决了,请及时标记有用的回复作为答案,这样会帮助遇到相同问题的人。
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
- 已建议为答案 Hart WangModerator 2017年4月3日 8:23
- 取消建议作为答案 Hart WangModerator 2017年5月18日 6:51