This question has already been answered:

Can you please write in simple language, what is needed in C # .NET? I more or less understand this example.

public string Location { get { return _location; } set { if (value != null) _location = value; } } 

But why are they used in this form?

 public string Make {get; set;} public string Model {get; set;} 

Reported as a duplicate by Grundy participants, Alexey Shimansky , Kromster , VladD c # Aug 16 '16 at 7:43 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • But why are they used in this form? - Help - Grundy
  • used for convenience, if you do not need additional logic when setting and getting the value - Ruslan_K

1 answer 1

It is more correct to make public properties, rather than fields, since the need to add logic to reading or writing may come unexpectedly, and if you have a public field this can cause problems. A property can also be defined in an interface that inherits a class, but a field does not. If a class inherits an interface, then most likely you will initially have just such fields.

Learn more about the differences: What are properties for?