c#中this的作用

来源:互联网 发布:天子星软件 编辑:程序博客网 时间:2024/05/21 12:42

1,代表当前类的实例化对象

2,能显示的调用当前类的构造方法

public class Student{ public string name; public int age; public string gender; public Student(string name,int age,string gender){    this.name=name;    this.age=age;    this.gender=gender;}//先是调用构造方法public Student(string name,string gender):this(name,0,gender)//0为年龄的默认值{//其他操作}  }

注意:

     this和base均为类的预定义对象,其属于类的对象,不属于类,静态方法和静态变量属于类,所以在静态方法中不能使用this和base

0 0
原创粉丝点击