Exposing Member Objects As Properties or Methods in .NET

后端 未结 7 1945
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-05 05:58

In .NET, if a class contains a member that is a class object, should that member be exposed as a property or with a method?

相关标签:
7条回答
  • 2020-12-05 06:19

    Property. A Property is basically just a 'cheap' method. Getting or setting a reference to an object is pretty cheap.

    Just to clarify, properties are usually supposed to represent the internal state of an object. However, the implementation of a member as a property or method tells the user how expensive the call is likely to be.

    0 讨论(0)
提交回复
热议问题