我一直在使用ReSharper來完成一些清理C#代碼庫的工作。我一直在使用模型類中的私有字段和公共屬性。但是,我發現我可以簡單地將沒有後臺字段的屬性轉換爲自動屬性。這些是模型類;它們中沒有任何方法影響對象中的數據。只使用自動屬性更好嗎?在沒有方法存在的類中是否需要私有字段?
編輯:包括例如「備份域」
public class Gizmo
{
//this is what I call the "backing" field, only because it's "behind" the
//publicly-accessible property and you access it through the property
private Int32 _count;
//and this is the property, of course
public Int32 Count
{
get { return _count; }
set { _count = value; }
}
}
你所說的「有沒有後備字段屬性」的意思是?如果你在這裏給出一個例子,它會減少混淆...... –