C# read-only calculated properties, should they be methods?

前端 未结 11 1184
刺人心
刺人心 2021-01-31 13:55

I have several entities that have calculated fields on them such as TotalCost. Right now I have them all as properties but I\'m wondering if they should actually be methods. Is

11条回答
  •  隐瞒了意图╮
    2021-01-31 14:49

    I think they should all be properties. As long as it doesn't change the state of the object, I'm cool with it as a property.

    Additionally, if I'm using your class for data binding (WPF, etc.), then I can bind directly to your property without having to modify/extend the class.

提交回复
热议问题