title: C# - Linq cast generic list to custom class
body: <p>I have declared a custom collection class like this:</p>
  
  <pre><code>public class WipCommesse
  {        
      private string FNumCommessa;
      private int FIdTipologia, FTotQtaLetta;
  
      public int IdTipologia
      {
          get { return FIdTipologia; }
          set { FIdTipologia = value; }
      }
  
      public string NumCommessa
      {
          get { return FNumCommessa; }
          set { FNumCommessa = value; }
      }
  
      public int TotQtaLetta
      {
          get { return FTotQtaLetta; }
          set { FTotQtaLetta = value; }
      }
  
  }
  
  public class WipCommesseList : List&lt;WipCommesse&gt;
  {
  
  }
  </code></pre>
  
  <p>In my code I use Linq to group another list and I want to cast to my custom type</p>
  
  <pre><code>   WipCommesseList wipGrouped = 
     (WipCommesseList)myList.GroupBy(x =&gt; new
                              {
                                  x.IdTipologia,
                                  x.NumCommessa
                              }).
                              Select(g =&gt; new WipCommesse()
                              {
                                  IdTipologia = g.Key.IdTipologia,
                                  NumCommessa = g.Key.NumCommessa,
                                  TotQtaLetta = g.Sum(i =&gt; i.QtaLanciabile)
                              }).ToList();
  </code></pre>
  
  <p>The definition of the class is the same but when i call ToList() method it return as System.Collection.Generic.List and the cast failed.</p>
  
  <p>What can I do to convert correctly  to my class ?</p>