属性访问器 [英] Property accessors

查看:112
本文介绍了属性访问器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



 公共字符串名称
{
得到
之间的根本区别{
返回_name;
}

{
_name =价值;
}
}

 公共字符串名称{;设置;} 


解决方案

  1. 您可以访问内部磁场,在第二种情况下它的自动生成

  2. 您可以设置在VS断点,第二你不能。


Is there any fundamental difference between

public string Name  
{  
  get  
  {  
    return _name;  
  }  
  set  
  {  
    _name = value;  
  }  
} 

and

public string Name {get; set;}

解决方案

  1. You can access internal field, in second case it's autogenerated
  2. You can set a breakpoint in VS, in second you cannot.

这篇关于属性访问器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆