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();
}
}
浙公网安备 33010602011771号