VS中是否有任何快捷方式可以从相应的属性定义字段?
答案 0 :(得分:10)
如果您要为自动生成的属性生成后备存储:
public string MyProperty { get; set; }
要:
public string _myProperty;
public string MyProperty {
get { return _myProperty; }
set { _myProperty = value; }
}
然后在Visual Studio中没有快捷方式。像Resharper and CodeRush这样的重构工具提供了此功能。
在Visual Studio中,"Encapsulate field"重构可以反过来 ctrl + r , e 。< / p>
public string _myProperty;
要:
public string _myProperty;
public string MyProperty {
get { return _myProperty; }
set { _myProperty = value; }
}