Why does it have to be a struct anyway? It's not a good design to have a struct hold a memory block. coz valuetype instances will be copied around when passed as parameters. Change struct to class will solve your problem. On the other hand, if you are trying to declear it as struct for some interop reasons, you may wanna try: [MarshalAs(UnmanagedType.ByValArray, SizeConst=40)] byte[] Name;
Test.Name[0]=??
{
int ID;
char[] Name=new char[40];
}
{
int ID;
char[] Name=new char[40];
}
{
int ID;
char[] Name=new char[40];
}提示错误:结构中不能有实例字段初始值设置项( Error CS0573 )。
It's not a good design to have a struct hold a memory block. coz valuetype instances will be copied around when passed as parameters.
Change struct to class will solve your problem. On the other hand, if you are trying to declear it as struct for some interop reasons, you may wanna try:
[MarshalAs(UnmanagedType.ByValArray, SizeConst=40)]
byte[] Name;
由C++生成的二进制文件(由struct描述),可就是找不到用C#读取二进制文件块到
struct的方法。还望C#高手指点。
{
int ID;
char[] Name;
}
更正确