Performance overhead for properties in .NET

前端 未结 9 1946
隐瞒了意图╮
隐瞒了意图╮ 2020-12-10 01:43

I read somewhere that having public properties is preferable to having public members in a class.

  1. Is this only because of abstaraction and modularity? Are

9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-10 02:21

    It is mostly for purposes of abstraction (you can later add validation without breaking existing code, or requiring recompilation).

    Even when using auto-properties, there is still a backing field generated by the compiler, and will perform as such.

提交回复
热议问题