title: Linq to collection (where clause)
body: <p>I am attempting to get the last added version of something in a collection.  In this collection is a '|' (pipe delimited string...) one of the pipe segments has a high number.  I am attempting to get a unique collection that has the highest number of all those strings... This sounds like it might be a mighty big deal, and I am not sure if linq can handle this.  (I don't use Linq that much so I am not to sure of what it can and can't do.  Is doing this sort of thing even possible?  If so, how would you implement it?  Simple algorithm is needed, no need for code, I just need an idea of where I need to go for this.</p>
  
  <p>Thanks.</p>
  
  <p><strong>UPDATE: code example of what I am trying to do...</strong></p>
  
  <pre><code>    List&lt;SelectListItem&gt; PatientList = new List&lt;SelectListItem&gt;();
              foreach (XmlNode node in nodeList)
              {
                  XmlDocument xDoc = new XmlDocument();
                  xDoc.LoadXml(node.OuterXml);
                  string popPatInfo = xDoc.SelectSingleNode("./template/elements/element[@name=\"FirstName\"]").Attributes["value"].Value + ", " + xDoc.SelectSingleNode("./template/elements/element[@name=\"LastName\"]").Attributes["value"].Value + " | " + DateTime.Parse(xDoc.SelectSingleNode("./template/elements/element[@name=\"DateOfBirth\"]").Attributes["value"].Value.Split('T')[0]).ToString("dd-MMM-yyyy");
                  string patientInfo = xDoc.SelectSingleNode("./template/elements/element[@name=\"PatientId\"]").Attributes["value"].Value + "|" + xDoc.SelectSingleNode("./template/elements/element[@name=\"PopulationPatientID\"]").Attributes["enc"].Value + "|" + xDoc.SelectSingleNode("./template/elements/element[@name=\"AdminDate\"]").Attributes["value"].Value;
                  PatientList.Add( new SelectListItem { Text = popPatInfo, Value = patientInfo });
              }
              var queryResults = PatientList.GroupBy(x =&gt; x.Value).Select(x =&gt; x.FirstOrDefault());
  </code></pre>
  
  <p>As you can see, I currently have a list that gets a unique entry from that collection.  I want that unique entry to also have the highest </p>
  
  <pre><code>    Node.Attributes["enc"].Value
  </code></pre>
  
  <p>Which is one of the pipes in the string as you can see.  I am wondering if this is even possible?</p>
  
  <p><strong>Update II</strong>
  Here is one way I attempted to do it, and this is just me trying to get a good grasp on linq...</p>
  
  <pre><code>    PatientList.GroupBy(x=&gt;x.Value.Split('|')[1].Max).Select(x =&gt; x.FirstOrDefault());
  </code></pre>
  
  <p><strong>UPDATE 3: Goal clarification</strong>
  I essentially need a list of unique selectListItems each member of that list has that maximum value...</p>
  
  <p><strong>UPDate Simple example</strong></p>
  
  <p>I will just have a simple example that won't have all the fields in the pipe delimited string that I posted earlier.  This is just an example after all...</p>
  
  <p>SelectListItem I have</p>
  
  <pre><code>    Text: Value1, Value: notUnique|0|endofstring
      Text: Value2, Value: notUnique|1|endofString
      Text: Value3, Value: notUnique|2|endofString
      Text: Value4, Value: Unique1|0|endofString
  </code></pre>
  
  <p>SelectListItem I want       </p>
  
  <pre><code>    Text: Value1, Value: notUnique|2|endofstring
      Text: Value1, Value: Unique1|0|endofstring
  </code></pre>