title: Public Fields versus Automatic Properties
body: <p>We're often told we should protect encapsulation by making getter and setter methods (properties in C#) for class fields, instead of exposing the fields to the outside world.</p>
  <p>But there are many times when a field is just there to hold a value and doesn't require any computation to get or set. For these we would all do this number:</p>
  <pre><code>public class Book
  {
      private string _title;
  
      public string Title
      {
            get =&gt; _title; 
            set =&gt; _title = value;
      }
  }
  </code></pre>
  <p>Well, I have a confession, I couldn't bear writing all that (really, it wasn't having to write it, it was having to look at it), so I went rogue and used public fields.</p>
  <p>Then along comes C# 3.0 and I see they added automatic properties:</p>
  <pre><code>public class Book
  {
      public string Title { get; set; } 
  }
  </code></pre>
  <p>Which is tidier, and I'm thankful for it, but really, what's so different than just making a public field?</p>
  <pre><code>public class Book
  {
      public string Title;
  }
  </code></pre>