就是在定义时,应该初始化,当改程序没有初始化,却成功运行,请问是怎么回事?
using System;
class Student
{
public Student(double allow, string demand, string location)
{
this.allow = allow;
this.demand = demand;
this.location = location;
}
public double allow;
public string demand;
public string location;
public static readonly Student Bechelor;
public static readonly Student Master;
public static readonly Student Doctor;
static Student()
{
Bechelor =new Student(200,"student","1#楼");
Master =new Student(1000,"creative","2#楼");
Doctor=new Student(2000,"inventive","3#楼");
}
}
class App
{
public static void Main()
{
Student student1=Student.Bechelor;
Console.WriteLine("该学生每月的津贴为:{0}",student1.allow);
Console.WriteLine("对该学生的培养标准shi:{0}",student1.demand);
Console.WriteLine("该学生住址:{0}",Student.Bechelor.location);
}
}
写错了,第一句话应该是:当改==但该