Exposing Member Objects As Properties or Methods in .NET

后端 未结 7 2053
爱一瞬间的悲伤
爱一瞬间的悲伤 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:17

    If all you are doing is exposing an object instance that is relevant to the state of the current object you should use a property.

    A method should be used when you have some logic that is doing more than accessing an in memory object and returning that value or when you are performing an action that has a broad affect on the state of the current object.

提交回复
热议问题