我一直在編碼類這樣當沒有特殊動作C#字段:我需要使用{get;組; }以獲取和設置
public class ReportViewModel
{
public string Status;
public string DataSource;
public String DataStore { get; set; }
public PageMeta PageMeta { get; set; }
public ICollection<Question> List { get; set; }
}
注意,大多數字段使用{獲得;組; }除了我讓Visual Studio爲我添加的前兩個。
我想知道的是我真的需要使用{get;組; }。在我看來,VS2010不會自動添加這個,所以我需要它嗎?
可能的重複[在C#中'Fields'和'Properties'有什麼區別?](http://stackoverflow.com/questions/4446929/what-is-the-difference-between-fields-and- properties-in-c) –
@FrédéricHamidi - 值得鏈接,但我認爲這個提問者是從不同的方向來解決這個問題的,因此這增加了作爲一個單獨問題的價值。 – Keith
[C#.NET 3.5+中屬性和字段之間的差異]的可能重複(http://stackoverflow.com/questions/653536/difference-between-property-and-field-in-c-sharp-net-3- 5) – nawfal