title: C# how to get the name (in string) of a class property?
body: <pre><code>public class TimeZone
  {
      public int Id { get; set; }
      public string DisplayName{ get; set; }
  }
  </code></pre>
  
  <p>In some other class I've:</p>
  
  <pre><code>   var gmtList = new SelectList(
         repository.GetSystemTimeZones(), 
         "Id",
         "DisplayName");
  </code></pre>
  
  <p><em>Note: System.Web.Mvc.SelectList</em></p>
  
  <p>I do not like to have to write the property name with "Id" and "DisplayName". Later in time, maybe the property name will change and the compiler will not detect this error.
  C# how to get property name in a string?</p>
  
  <p><strong>UPDATE 1</strong></p>
  
  <p>With the help of Christian Hayter, 
  I can use:</p>
  
  <pre><code>var tz = new TimeZone();
  var gmtList = new SelectList(
      repository.GetSystemTimeZones(), 
      NameOf(() =&gt; tz.Id), 
      NameOf(() =&gt; tz.TranslatedName));
  </code></pre>
  
  <p>OR</p>
  
  <pre><code>var gmtList = new SelectList(
      repository.GetSystemTimeZones(), 
      NameOf(() =&gt; new TimeZone().Id), 
      NameOf(() =&gt; new TimeZone().TranslatedName));
  </code></pre>
  
  <p>If someone has other idea without the need of creating a new object. Feel free to share it :) thank you.</p>