title: Why do we create a private variable inside a class and then set property?
body: <p>Why do we create a private variable inside a class and then make a public property out of it on the following lines in c#?
  Also I do not get the concept of getting and setting a property.</p>
  
  <p>I mean why do we do this   </p>
  
  <pre><code> public class MyClass
      {
          private string _myProperty;
  
          public string MyProperty
          {
             get
             { return _myProperty; }
             set
             { _myProperty = value; }
      }
  </code></pre>
  
  <p>or this </p>
  
  <pre><code>public class MyClass
  {
      public string MyProperty {get;set;}
  }
  </code></pre>
  
  <p>My question is much similar to this one:
  <a href="https://stackoverflow.com/questions/4423197/why-do-we-need-to-create-class-variables-to-get-and-set-a-property">Why do we need to create class variables to get and set a property?</a></p>
  
  <p>The above thread didn't seem to solve my problem. Somebody, please elaborate on :</p>
  
  <ul>
  <li>Why do create private variables first and then make public properties out of it? Why not a single step?</li>
  <li>What do we need 'get' and 'set'? why two approaches to use it, what are the differences?</li>
  </ul>
  
  <p>The question's answer might be too long. But even if you spend your valuable time just to explain a single point properly, I'll be more than obliged. Thanks in advance :)</p>