this 的用法不是很懂!想请那为高手给点例子+讲解!

解决方案 »

  1.   

    摘自MSDN
    -----------------------------------
    this 关键字引用类的当前实例。 以下是 this 的常用用途:限定被相似的名称隐藏的成员,例如:  复制代码 
    public Employee(string name, string alias) 
    {
        this.name = name;
        this.alias = alias;

     将对象作为参数传递到其他方法,例如:   复制代码 
    CalcTax(this);
     声明索引器,例如:   复制代码 
    public int this [int param]
    {
        get { return array[param];  }
        set { array[param] = value; }
    }
     
      

  2.   

    msdn上有,2楼即是,望有人可以再多补充!
      

  3.   

    1.限定被相似的名称隐藏的成员. 
    2.将对象作为参数传递到其他方法. 
    3.声明索引器.public class Person
    {
    private int age;
    private string name;
    public Person():this(20,"匿名")//调用带两个参数的构造函数
    {}public Person(int age):this(age,"匿名")//调用带两个参数的构造函数
    {
    }public Person(string name):this(20,name)//调用带两个参数的构造函数
    {
    }public Person(int age,string name)
    {
    this.age=age;
    this.name=name;
    }
    }
      

  4.   

    4楼的老师学生愚昧    
        public Person(int age,string name)
       {
       this.age=age;//两个age不知道谁是谁啊?
       this.name=name;//同上面一样!
       }
      

  5.   


    所以需要个this来限定啊!
    带this的是类的私有变量,不带的那个就是函数的参数