Why using only setter in property declaration?

后端 未结 4 577
北荒
北荒 2021-01-26 09:32
int MyProperty { set; }

What\'s the idea for using only setter on property? If we set one property with some value, I guess it\'s very likely to read t

4条回答
  •  失恋的感觉
    2021-01-26 10:12

    You normally don't create a property like this. As you say, it doesn't have much value.

    If you really want to allow only setting a certain value without reading it, then provide a method. That's cleaner.

提交回复
热议问题