title: Cast/Convert IEnumerable<T> to IEnumerable<U>?
body: <p>The following complies but at run time throws an exception. What I am trying to do is to cast a class PersonWithAge to a class of Person. How do I do this and what is the work around?</p>
  
  <pre><code>class Person
  {
      public int Id { get; set; }
      public string Name { get; set; }
  }
  
  class PersonWithAge
  {
      public int Id { get; set; }
      public string Name { get; set; }
      public int Age { get; set; }
  }
  
  class Program
  {
      static void Main(string[] args)
      {
          IEnumerable&lt;PersonWithAge&gt; pwa = new List&lt;PersonWithAge&gt;
          {
              new PersonWithAge {Id = 1, Name = "name1", Age = 23},
              new PersonWithAge {Id = 2, Name = "name2", Age = 32}
          };
  
          IEnumerable&lt;Person&gt; p = pwa.Cast&lt;Person&gt;();
  
          foreach (var i in p)
          {
              Console.WriteLine(i.Name);
          }
      }
  }
  </code></pre>
  
  <p><strong>EDIT:</strong> By the way PersonWithAge will always contain the same properties as Person plus a couple more.</p>
  
  <p><strong>EDIT 2</strong> Sorry guys but I should have made this a bit clearer, say I have two db views in a database that contains the same columns but view 2 contains 1 extra field. My model view entities are generated by a tool that mimics the database views. I have a MVC partial view that inherits from one of the class entities but I have more than one way to grab data...</p>
  
  <p>Not sure if this helps but it means that I cant make personWithAge inherit from person.</p>