C#中给结构体内的数组赋值

unsafe public struct RAIN_COORDLINE
{
public fixed int horline[111]; //111条水平线的纵坐标
public fixed int verline[154]; //154条竖直线的横坐标
}
RAIN_COORDLINE rc =new RAIN_COORDLINE();

赋值的时候
rc.horline[0] = log.Horline[0];
编译通不过,提示:
不能使用非固定表达式中包含的固定大小缓冲区。请尝试使用 fixed 语句。

以前没接触过unsafe代码,不过刚才试了了一下。
不能使用非固定表达式中包含的固定大小缓冲区是说
RAIN_COORDLINE rc =new RAIN_COORDLINE();是一个非固定表达式,而rc.horline[0]使用了非固定表达式里面的固定大小缓冲区。
改成
fixed(RAIN_COORDLINE* rc1 = &rc)
{
rc1->horline[0]=log.Horline[0];
}
温馨提示:答案为网友推荐,仅供参考