title: calculating age in c# simple yet
body: <p>I have a property <code>DateOfBirth</code> and a property <code>Age</code>.</p>
  
  <p><code>DateOfBirth</code> is <code>DateTime</code> datatype and <code>Age</code> is <code>int</code> datatype.</p>
  
  <p>I want to calculate the person's age inside the constructor, and I have:</p>
  
  <pre><code>private int CalculateAge(DateTime birthDate, DateTime now)
  {
     int age = now.Year - birthDate.Year;
     if (now.Month &lt; birthDate.Month || (now.Month == birthDate.Month &amp;&amp; now.Day &lt; birthDate.Day))
     {
        age--;
     }            
     return age;
  }
  
  public virtual DateTime? Dob { get; set; }
  public virtual int Age { get; set; }
  
  public MyObject()
  {
     Age = CalculateAge(Dob, DateTime.Now);
  }
  </code></pre>
  
  <p>At compile time I'm getting the following errors:</p>
  
  <blockquote>
    <p>The best overloaded method match for ... has some invalid arguments</p>
  </blockquote>
  
  <p>and</p>
  
  <blockquote>
    <p>cannot convert from 'System.DateTime?' to System.DateTime</p>
  </blockquote>