title: C#, using ++ operator on value obtained via property (get)
body: <p>In C# we define a property as follows:</p>
  <pre><code>// m_age is a private int in the class Employee
  public int Age
  {
      get {return m_age;}
      set {m_age = value;}
  }
  </code></pre>
  <p>Now, when I do</p>
  <pre><code>static void Main()
  {
      Employee e = new Employee(age: 28); // Create new Employee
      System.Console.WriteLine(&quot;Age: {0}&quot;, e.Age); // Prints 28
      
      // Now increase age by 1
      ++e.Age;
  
      System.Console.WriteLine(&quot;Age: {0}&quot;, e.Age); // Prints 29
  }
  </code></pre>
  <p>Why does the</p>
  <pre><code>++e.Age;
  </code></pre>
  <p>work? I did some searching and found <a href="https://stackoverflow.com/questions/5274752/properties-by-value-or-reference">Properties - by value or by reference?</a></p>
  <p>This post had an answer:</p>
  <blockquote>
  <p>Technically it's always by value, but you have to understand what is being passed. Since it's a reference type, you are passing a reference back (but by value).</p>
  <p>Hope that makes sense. You always pass the result back by value, but if the type is a reference you are passing the reference back by value, which means you can change the object, but not which object it refers to.</p>
  </blockquote>
  <p>(I do have a good understand of value-types and reference-types, hence my confusion).</p>
  <p>Now, if indeed</p>
  <pre><code>e.Age
  </code></pre>
  <p>returns a <strong>copy</strong> of m_age (int is a value-type), won't we apply the increment ++ to the copy?</p>
  <p>Or...is the following true?</p>
  <pre><code>++e.Age;
  </code></pre>
  <p>is exactly the same/gets translated to</p>
  <pre><code>e.Age = e.Age + 1
  </code></pre>
  <p>only that</p>
  <pre><code>++e.Age;
  </code></pre>
  <p>returns a value (the value of e.Age after it has been incremented) whereas</p>
  <pre><code>e.Age = e.Age + 1
  </code></pre>
  <p>is an assignment and does not return a value (like C++ would do for example).</p>