title: How get max value by lambda query in C#?
body: <p>I want to get the last number in the code column in C# using the query lambda. Be careful that I want a numerical value, not a list. For example, if the last registered number was 50, I would like this number 50. That is, we can store the query result in a numerical variable so that I can use it elsewhere</p>
  
  <pre><code>var maxcode= dbContext.personel
                        .Select(a =&gt; a.Max(w =&gt; w.code))
                        .FirstOrDefault();
  </code></pre>
  
  <p>For example </p>
  
  <pre><code> code name     old
   -----------------
   1    Amelia   18
   2    Olivia   27 
   3    Emily    11
   4    Amelia   99
  </code></pre>
  
  <p>I want to get number 4 </p>
  
  <p>If I want to use top(1)  to improve the speed?</p>