private readonly PlayerCollection players = new PlayerCollection();
public PlayerCollection Players { get { return players; } }
public PlayerCollection Players { get; private set; }
public MyClass()
{
Players = new PlayerCollection();
}
這將是最好?有兩種方法中最適合的環境嗎?
我不同意「幾乎從不使用私有和只讀」,因爲它防止你改變對象的值(當它是私有的時候)是非常有用的。實際上我會說公共只讀組合不太有用,因爲你很少需要公共領域(屬性通常更合適)。 – asmo
我一直使用'private readonly'作爲「常量」,在編譯時無法知道緩存鍵或字體對象。 – millimoose