这是个构造函数,this.name指当前类的属性,后一个name是构造函数中的参数
这就是给类中的属性赋值
这样写就清楚了
public Employee(string strName, string strAlias)
{
// Use this to qualify the fields, name and alias:
this.name = strName;
this.alias = strAlias;
}
this关键字可以代替当前类,也就是说A类中出现的this指的是A类,B类中出现的this指的是B类。
this.name=name;是当前类的name属性赋值.(通过Employee方法)
总的来说:this可指代对象自己本身: 当在一个类中要明确指出使用对象自己的属性或方法时就应该加上this引用。还有很多的用法:
参考:http://fishlee.javaeye.com/blog/211442
比如说定义一个类A:(写的很简单)
class A{
private string name;
public set(string name)
{
this.name=name
}
前一个name指的是A类中的私有数据成员,后一个name指的是set(string name)中传入的参数。 this指的是当这个类被实例化之后形成的对象的默认指针。