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

前端 未结 11 1368
刺人心
刺人心 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:25

    If they are a) lightweight and b) have no side effects, I would make them Properties.

    Lightweight is a bit fuzzy of course, but the rule of thumb is: If I ever have to worry calling a Property (be it in a loop or anywhere else), it should possibly be a method.

提交回复
热议问题