C# 属性
C#中两个概念. 域 和 属性
域(field) 即字段.
C# 推荐采用属性来表达
属性提供了只读(get),只写(set),读写(get和set)三种接口操作
自动属性(Auto-Implemented Properties)
public class Student
{
public string Name { get; set; }
}
等效于:
public class Student
{
private string name; // This is the so-called "backing field"
public string Name // This is your property
{
get {return name;}
set {name = value;}
}
}