title: C# Property Access Optimization
body: <p>In C# (or VB .NET), does the compiler make attempts to optimize property accesses? For eg.,</p>
  
  <pre>
  <code>
  public ViewClass View
  {
      get
      {
          ...
          Something is computed here
          ....
      }
  }
  
  if (View != null)
      View.Something = SomethingElse;
  
  </code>
  </pre>
  
  <p>I would imagine that if the compiler could somehow detect that <code>View</code> remains constant between the two accesses, it can refrain from computing the value twice. Are these kind of optimizations performed?</p>
  
  <p>I understand that if <code>View</code> has some intensive computations, it should probably be refactored into a function (<code>GetView()</code>). In my particular case, <code>View</code> involves climbing the visual tree looking for an element of a particular type.</p>
  
  <p>Related: Any references on the workings of the (Microsoft) C# compiler?</p>