5.结构体

class Program
{
//定义结构体
public struct Student
{
private string stuName;
private int stuId;
private int age;
public void GetValue(string name, int stuid, int _age)
{
stuName = name;
stuId = stuid;
age = _age;
}
public void display()
{
Console.WriteLine(stuName + " ; " + stuId + " ; " + age + " ; ");
}

    }


    static void Main(string[] args)
    {
        //使用结构体
        Student objstructStu = new Student();
        objstructStu.GetValue("小王", 1006, 23);
        objstructStu.display();

        //注意结构体和类的区别
        //Student objstructStu1 = new Student()
        //    {
        //       stuName="大好河山" 
        //    };

        Console.Read();
    }
}
posted on 2020-12-29 17:58  cq752522131  阅读(61)  评论(0)    收藏  举报