在跟着刘铁猛老师学习的过程里, This,不太明白 例如下面这段代码 注释的地方去掉 this.
时间: 2020-08-20来源:V2EX
前景提要
namespace PropertyExamples{ class Program { static void Main(string[] args) { try { Student stu1 = new Student(); stu1.SetAge(20); Student stu2 = new Student(); stu2.SetAge(20); Student stu3 = new Student(); stu3.SetAge(200); int avgAge = (stu1.GetAge() + stu2.GetAge() + stu3.GetAge() / 3); Console.WriteLine(avgAge); } catch (Exception wx) { Console.WriteLine(wx.Message); } } } class Student { private int age; public int GetAge() { return this.age; // 请看这里 } public void SetAge(int value) { if (value>=0 && value <= 120) { this.age = value; // 请看这里 } else { throw new Exception("Age value has error"); } } } }

科技资讯:

科技学院:

科技百科:

科技书籍:

网站大全:

软件大全:

热门排行