Why we need Properties in C#

前端 未结 8 1192
萌比男神i
萌比男神i 2020-12-01 09:31

Can you tell me what is the exact usage of properties in C# i mean practical explanation

in our project we are using properties like

/// 

        
8条回答
  •  庸人自扰
    2020-12-01 10:27

    Lots of reasons:

    • Semantics. Properties separate the implementation of your type from the interface.
    • Binary Compatibility. If you ever need to change a property, you can do so without breaking binary compatibility for dependent code. With fields, you have to recompile everything even if the new implementation uses a property with the same name.
    • Databinding. You can't databind to a field.

提交回复
热议问题