title: linq query to find the objects that are the maximum and the minimum
body: <p>I have a list of DailyValue structs called stockValues. I need to find the object with the maximum and the minimum <code>High</code> value.</p>
  
  <p>(Here is the struct for reference's sake)</p>
  
  <pre><code>struct DailyValues
  {
          public DateTime Date { get; private set; }
          public decimal Open { get; private set; }
          public decimal High { get; private set; }
          public decimal Low { get; private set; }
          public decimal Close { get; private set; }
          public decimal Volume { get; private set; }
          public decimal AdjClose { get; private set; }
  }
  </code></pre>
  
  <p>I've tried a couple various things, </p>
  
  <pre><code>var mx = stockValues.Max(sv =&gt; sv.High);
  </code></pre>
  
  <p>Only gives me the correct maximum value, but it does not let me access the whole object and it's members (what I want is the actual value AND the date it occurred). So I attempted this:</p>
  
  <pre><code>var stuff = from s in stockValues
                          group s by s.Date into g
                          where g.Max(x =&gt; x.High)
                          select g;
  </code></pre>
  
  <p>However, this just underlines <code>g.Max(..)</code> and states that the compiler cannot implicitly convert a decimal into a boolean. While I am not new to C#, I have no experience with Linq and cannot seem to wrap my mind around it quite correctly (I'm sure this is very simple, I'm just not doing it right). Can anyone steer me correctly? </p>
  
  <p>As always, thanks to all in advance!</p>