On one hand, I know that the advisable usage of Properties is to have a backing field, like in the following example:
private int m_Capacity;
public int Capacity
{
get { return m_Capacity > 0 ? m_Capacity : -666; }
set { m_Capacity = value; }
}
On the other hand, what benefit do I get from using the above example over discarding the field and using only the property for all purposes, like in the following example:
public int Capacity
{
get { return Capacity > 0 ? Capacity : -666; }
set { Capacity = value; }
}
What is good about using a backing field for regular (non-auto-implemented) properties?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…