想请教高手们多给一点关于c#中this 的用法和一些例子!谢谢了! this 的用法不是很懂!想请那为高手给点例子+讲解! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 摘自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; }} msdn上有,2楼即是,望有人可以再多补充! 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楼的老师学生愚昧 public Person(int age,string name) { this.age=age;//两个age不知道谁是谁啊? this.name=name;//同上面一样! } 所以需要个this来限定啊!带this的是类的私有变量,不带的那个就是函数的参数 C#如何在一个项目里面调用另一个项目的函数? C# 图片 流 转成视频保存起来 C#会计(金额)打印,问题,如何从右到左,逐个打印 中恒基超级旋风数字监控系统 如何用在程序中? 新手关于c#的问题 急求各位技术牛哥,WINDOWS 桌面应用程序怎么实现翻页效果 sqlexpress遇到的奇怪的问题,麻烦大家帮忙看下 如何向其他程序发送消息 如何用C#实现发SOAP数据包? 如何获得其他的鼠标事件? private set和不设set属性有什么区别 大家有什么好的报表工具推荐?须能进行运行时设计~
-----------------------------------
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.将对象作为参数传递到其他方法.
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;
}
}
public Person(int age,string name)
{
this.age=age;//两个age不知道谁是谁啊?
this.name=name;//同上面一样!
}
所以需要个this来限定啊!
带this的是类的私有变量,不带的那个就是函数的参数