I have classes which have automatic properties only like public customerName {get; set;}. They are public because they are accessed outside the class. They can also be accessed inside the class. They offer good encapsulation and better debugging. I can put a breakpoint on one if I need to know who is accessing it and when.
My question is what are the disadvantages of using properties only with no corresponding fields? I can make the setter or getter private, internal.. etc which means I also have flexibility of scoping it when needed.
Serialization with
BinaryFormatter– you have big problems if you need to change your property to a “regular” property later, for example to add some validation / eventing /etc – sincBinaryFormatteruses the field names. And you can’t duplicate this, since the field name the compiler generates cannot be written as legal C#.Which is a good reason to look at a contract-based serializer instead. See this blog entry for more info.