我在将Student命名为Student类中的静态变量时遇到错误。 任何人都可以帮我找到它。
class Student
{
public int SId;
public string SName;
public Student(int SId)
{
this.SId = SId;
Console.WriteLine("Constructor is called");
}
static string coll = new string ();
cool = "RVIM"
我收到以下错误。
Error 1 Invalid token '=' in class, struct, or interface member declaration C:\Users\amruthap\AppData\Local\Temporary Projects\ConsoleApplication1\Student.cs 18 14 ConsoleApplication1
Error 2 'string' does not contain a constructor that takes 0 arguments C:\Users\amruthap\AppData\Local\Temporary Projects\ConsoleApplication1\Student.cs 17 37 ConsoleApplication1
Error 3 'ConsoleApplication1.Student.coll' is a 'field' but is used like a 'type' C:\Users\amruthap\AppData\Local\Temporary Projects\ConsoleApplication1\Student.cs 18 9 ConsoleApplication1
}
答案 0 :(得分:4)
你不能调用默认的字符串构造函数 - String class没有ctor采用0参数..尝试将coll设置为“”
答案 1 :(得分:2)
string不包含带0参数的构造函数
第二件事cool = "RVIM"
=
类结构或接口成员声明中的无效标记。
答案 2 :(得分:1)
不要调用字符串构造函数...尝试将其视为值类型
static string coll =“”;