Property vs Function (specifically .NET)

后端 未结 6 2082
花落未央
花落未央 2021-01-12 11:20

I\'ve read some discussions about this subject, and there\'s something I just don\'t understand.

The most common answer seems to be this: use a ReadOnly Property to

6条回答
  •  旧时难觅i
    2021-01-12 12:09

    "Cached data -> Public variable" - bad idea. This would allow another class to modify the cached data. Also, computing the data for caching might be expensive: using a read-only property allows you to defer calculation until the property is accessed.

提交回复
热议问题