Exposing Member Objects As Properties or Methods in .NET

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

    I confused about the using property and method before. But now I am using this rule according to MSDN Guideline:

    methods represent actions and properties represent data. Properties are meant to be used like fields, meaning that properties should not be computationally complex or produce side effects. When it does not violate the following guidelines, consider using a property, rather than a method, because less experienced developers find properties easier to use.

提交回复
热议问题