当前位置: 代码迷 >> C# >> 新手有关问题:this关键字理解不好。
  详细解决方案

新手有关问题:this关键字理解不好。

热度:92   发布时间:2016-05-05 04:16:53.0
新手问题:this关键字理解不好。。
public class ShoppingBookItem
{
    private string strName;
    private float fPrice;
    public ShoppingBookItem(string name,float price)
    {
               this.strName = name;
               this.fPrice=price;
 
   }
}

网上查了很多,还是理解不好这个this关键字,是代表ShoppingBookItem声明的对象的意思么? 不理解。。囧。。
------解决思路----------------------
this代表当前对象,就是当前这个类的实例化对象
------解决思路----------------------
this(中文释义:这个) 表示当前类实例化的对象
在 C# 中,如果没有歧义的话可以省略
注意:静态方法和属性是没有 this 的,用错了反而不好。
所以应淡化 this 的使用

------解决思路----------------------
this关键字引用类的当前实例
------解决思路----------------------
this = 我
  相关解决方案