Why do I need a private field that is exposed via public property?

前端 未结 11 737
天涯浪人
天涯浪人 2020-12-11 11:41

I\'m comming from Java world mainly. So, C# properties do look nice.

I know that with C# 3.0 or above I can use Automatic Properties. I like it even more :).

11条回答
  •  臣服心动
    2020-12-11 12:03

    In this case you don't require it. If you ever need to do anything else in the setter or getter, though, the automatic property won't work -- you'll need the private field to manipulate.

提交回复
热议问题