Why can't we use public fields for data binding in C#?

后端 未结 3 1928
暖寄归人
暖寄归人 2021-02-13 15:10

I am aware of the advantages of using properties over fields, like being able to provide additional logic when required in the future.

But I really wonder why it\'s not

3条回答
  •  遇见更好的自我
    2021-02-13 16:02

    Since you can't declare Fields in Interfaces, you should not use Public Fields. All fields should be private only.

    If your code depends upon Abstractions, you need to use Interfaces and here the Public Fields are not available.

提交回复
热议问题