Any reason to use auto-implemented properties over manual implemented properties?

前端 未结 7 1311
Happy的楠姐
Happy的楠姐 2020-11-27 07:22

I understand the advantages of PROPERTIES over FIELDS, but I feel as though using AUTO-implemented properties over MANUAL implemented properties doesn\'t really provide any

7条回答
  •  眼角桃花
    2020-11-27 07:48

    Auto-implemented properties are not guaranteed to keep the same backing field name between builds. Therefore, it is theoretically possible that serializing an object in one version of an assembly, and then re-serializing that same object in another assembly could cause breaking changes.

    This is highly unlikely, but it is a valid concern if you're trying to maintain the ability to "swap out" version of your assemblies for newer versions.

    By using manually implemented properties, you're guaranteed that the backing field never changes (unless you change it specifically).

    Aside from that minute difference, an auto-property is a normal property that is implemented automatically with a backing field.

提交回复
热议问题