结构体的对象使用new运算符创建(obj)也可以直接创建单个元素赋值(obj2)这是与类不同的因为类只能使用new创建对象
程序:
- public struct student {
- public int x; public int y;
- public static int z; public student(int a,int b,int c)
- { x=a;
- y=b; student.z=c;
- } };
- class program {
- public static void Main() {
- student obj=new student(100,200,300); student obj2;
- obj2.x=100; obj2.y=200;
- student.z=300; }
- }










