[StructLayout(LayoutKind.Sequential)]
public struct Point
{
public int x;
public int y;
}
谁帮我解释一下这段程序的意思,以及StructLayout的用途,用法.
public struct Point
{
public int x;
public int y;
}
谁帮我解释一下这段程序的意思,以及StructLayout的用途,用法.
public struct Point
{
public int[] x=new int[];
}
提示:结构中不能有实例字段初始值设定项;
是不是结构里面不能定义数组的?
是不是结构里面不能定义数组的?结构不能在定义的时候,进行初始化,同时不能用new来初始化对象因此如下两种形式都是错误的
struct Test
{
int i = 1;//Can't be compiled
}struct Test
{
int[] i = new int[2];//Can't be compiled
}
分离的方法有两种,
一个是在构造函数中进行初始化,但是有缺陷,毕竟无法屏蔽默认构造函数;
struct Test
{
int[] i;
public Test( int Num )
{
i = new int[Num];
}
}
一个是通过属性来进行初始化。
struct Test
{
private int[] i;
public int[] I
{
get{ if( i == null ) i = new int[Num];
return i;}
}
}