C#中,为什么结构体也可以设置构造函数?
Using System;struct student
{
public int no;
public string name;
public photo;
public student(int stu_no,string stu_name,string stu_photo) //每条语句都要加一个public吗?为什么 {
no=stu_no;
name=stu_name;
photo=stu_photo;
} //结构体不是类,干嘛要定义构造函数?
class studenttest
{
public static void main()
student stu=new student(95001,"maiiho","123456"); //结构体对象?完全做类处理了... Console.WriteLine(stu.no);
Console.WriteLine(stu.name);
Console.WriteLine(stu.photo);
}
}