title: How to convert Generic List<anonymous type > to Generic List <Classname>?
body: <p>I have a database, where the CPU usage is inserted for every 'n' seconds and my task is to get the latest CPU entry from the database. I would like to display the latest CPU entry from the database tat belongs to the particular server , and I would like to save the result into a generic list.</p>
  
  <p>what I have tried, </p>
  
  <pre><code>    string match = "ServerX"
  
      List&lt;UsageCPU&gt; cpus = (from a in db.UsageCPUs
                            where a.ServerID.Contains(match)
                            group a by a.ServerID into b
                            orderby b.Key
                            select new { ServerID = b.Key, 
                            Usage = b.FirstOrDefault() }).ToList();
  </code></pre>
  
  <p>and I would like to loop through the result <code>cpus</code> to perform further other steps.</p>
  
  <p>but I get the following error</p>
  
  <blockquote>
    <p>Cannot implicitly convert type
    'System.Collections.Generic.List&lt;AnonymousType#1>' to
    'System.Collections.Generic.List&lt;FNC_RAQIT_HM_UI.UsageCPU>'.</p>
  </blockquote>
  
  <p>EDIT</p>
  
  <p><img src="https://i.stack.imgur.com/LI9Dz.png" alt="enter image description here">
  <strong>UPDATE</strong>
  The following query from Satpal worked for me.. but using <code>var</code></p>
  
  <pre><code>   var cpus = (from a in db.UsageCPUs
                      where a.ServerID.Contains(match)
                      group a by a.ServerID into b
                      orderby b.Key
                      select new
                      {
                          ServerID = b.Key,
                          Usage = b.FirstOrDefault().Usage
                      }).ToList();
  
          foreach (var item in cpus)
          {
             if(bla bla..)
          }
  </code></pre>
  
  <p>kindly help !!  </p>