每次我使用
this._Something
,我的 this.
变成了浅蓝色,并有绿色下划线。在按 F5 后,我无法获取值 101,而是得到了值 0。请帮忙解决一下?class Student
{
private int _ID;
public void SetID(int Id)
{
if (Id <= 0)
{
throw new Exception("It is not a Valid ID");
this._ID = Id;
}
}
public int GetID()
{
return this._ID;
}
}
class Program
{
public static void Main()
{
Student C1 = new Student();
C1.SetID(101);
Console.WriteLine("Student ID = {0}", C1.GetID());
}
}
this._ID = Id;
应该放在if {}
外面,否则它将永远不会被写入。将鼠标悬停在下划线符号上/查看左侧边缘,VS 将告诉您它的问题所在。 - Alex K.