众所周知在语句中 this 经常会出现在不同的方法中:
(1) 在构造方法中:
- private double a;
- private double b;
- public Area(double a,double b)
- {
- this.a=a;
- this.b=b
- }
其中的 this.a 代表的是定义的字段中的 a;
(2) 当定义一个类时, 如果此类没有进行调用 (
- Class Person{
- private string name;
- private int age;
- public void write()
- {
- Console.WriteLine("写作业");
- }
- public Person(string name,int age)
- {
- this.name=name;
- this.age=age;
- }
- }
其中当对该类没有进行实例化调用的话其中的 this 就是代表类中所在的字段
(3) 当对上面的类进行实例化后:
Person p=new Person("123",11);
其中的 this 所代表的内容就会改变为实例化中所体现的内容!!!
来源: http://www.bubuko.com/infodetail-2498055.html