What is the difference between a field and a property in C#?

C# OOP Basic Fresher Conceptual 1 min read

Quick Answer

A field is a variable that directly holds data. A property is a pair of accessor methods (get/set) that look like a field to callers but let you add logic, validation, change notification, computed values, or different accessibility on get vs set. Expose properties, not public fields.

A field just stores a value. A property is a get and/or set method pair that behaves like a field syntactically but can do more — validate the value, compute it on the fly, raise a change event, or be readable publicly but only settable privately. The practical reason I always use properties instead of public fields, even a plain auto-property with no logic, is that I can add logic later without changing the API. Switching a public field to a property is a breaking change.

  • Auto-property: public string Name { get; set; } — the compiler generates a hidden backing field.
  • You can start with an auto-property and add logic later without breaking callers — you can't do that with a public field (it changes the API / breaks binary compatibility).
  • { get; init; } for immutable-after-construction; { get; private set; } for read-only to the outside.
  • Expression-bodied computed property: public string FullName => $"{First} {Last}";.