C# protected property or field

后端 未结 5 1374
离开以前
离开以前 2021-01-01 13:47

Do you think it\'s better to always make protected class members an auto-implemented protected property to keep isolation or make it protected field is enough?



        
5条回答
  •  無奈伤痛
    2021-01-01 13:55

    Generally, you should use autoproperties - this allow you to easily add verification, or anything else you need later on. This is especially important if the protected member will be used by classes outside your assembly, as adding such code won't break your contract with them, whereas changing a field to a method or property will.

提交回复
热议问题