黑马程序员技术交流社区

标题: this 除了这样用,还有其他的用法么 [打印本页]

作者: 秦二江    时间: 2013-3-15 13:49
标题: this 除了这样用,还有其他的用法么
class Student         
{            
public Student(string name)        
{         
this.name =name; //this.name 表示当前类的字段。      
  }      
   private string name;         
public string Name()        
{         
get{  retrun name ;}               
   }         
}
还有什么用法?
作者: 曾玉锋    时间: 2013-3-15 14:02
索引器
public 类型 this[int index]
{
   get;
   set;
}

扩展方法
    public static class test
    {
        public static void GetName(this String str)
        {
            Console.WriteLine(str);
        }
    }

这个类的中的this 表示当前对象,String 是要扩展的类型  str是变量
(具体的就不详细描述了,网上可查)

this()  还可表示调用对应的重载方法,或者是构造函数




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2