c#3.0加入的一些新特性——自动实现属性
3.自动实现属性
在.NET2.0中属性是这样写的
//私有字段
private string _name;
//共有字段
public string Name
{
get { return _name; }
set { _name = value; }
}
可是.NET3.0新加入一种写法
public string Name { get; set; }
3.0中他更简洁了,可实际上编译器编译的时候是有私有字段的
3.自动实现属性
在.NET2.0中属性是这样写的
//私有字段
private string _name;
//共有字段
public string Name
{
get { return _name; }
set { _name = value; }
}
可是.NET3.0新加入一种写法
public string Name { get; set; }
3.0中他更简洁了,可实际上编译器编译的时候是有私有字段的