title: Using Linq or Lambda to compare items in nested collections
body: <p>I have an object which looks something like this  </p>
  
  <p><strong>Object</strong>  </p>
  
  <ul>
  <li>Name   </li>
  <li>ID   </li>
  <li>PropertyGroupList[]<br>
  <ul>
  <li><strong>PropertyGroupListItem</strong>
  <ul>
  <li>PropertyList[]
  <ul>
  <li><strong>PropertyListItem</strong>
  <ul>
  <li>Tag</li>
  <li>Type</li>
  </ul></li>
  <li><strong>PropertyListItem</strong>
  <ul>
  <li>Tag</li>
  <li>Type</li>
  </ul></li>
  </ul></li>
  </ul></li>
  <li><strong>PropertyGroupListItem</strong>
  <ul>
  <li>PropertyList[]
  <ul>
  <li><strong>PropertyListItem</strong>
  <ul>
  <li>Tag</li>
  <li>Type</li>
  </ul></li>
  <li><strong>PropertyListItem</strong>
  <ul>
  <li>Tag</li>
  <li>Type  </li>
  </ul></li>
  </ul></li>
  </ul></li>
  </ul></li>
  </ul>
  
  <p>Each of those objects has a PropertyListItem where the Tag is "Revision". I need to compare the value of "Revision" with all of the other objects stored in the list and return the item where "Revision" has the highest value.</p>
  
  <p>I think I can build a way with nested <code>for</code> loops but I thought it would be a better approach to get the Object by using a Linq or Lambda expression.  </p>
  
  <p>I've been trying to find a way to do this by myself but I feel like everything I did is completely wrong. I'd be more than happy if someone could help me and give a little explanation about it. Thanks a lot!</p>
  
  <p>EDIT:</p>
  
  <p>Sample code:</p>
  
  <pre><code>    public MdsObject GetSoftwareObjectByName(string sPackageName)
      {
          GetObjectListRequest getObjectListReq = new GetObjectListRequest();
          InitializeRequest(getObjectListReq);
          //TODO: Are there more characters which need to be escaped in an LDAP query to DSM?
          sPackageName = sPackageName.Replace("(", "\\(");
          sPackageName = sPackageName.Replace(")", "\\)");
          getObjectListReq.LdapQuery = "&lt;LDAP://rootDSE&gt;;(Name:IgnoreCase=" + sPackageName + ");;subtree";
          getObjectListReq.MaxResults = -1;
          GetObjectListReply getObjectListReply = AdministrationService.GetObjectList(getObjectListReq);
  
          switch (getObjectListReply.ObjectList.Length)
          {
              case 0:
                  { throw new ApplicationException("GetSoftwareObjectByName failed. Could not find '" + sPackageName + "'"); }
              case 1:
                  {
                      MdsObject incompleteObjectFromLdap = getObjectListReply.ObjectList[0];
                      return GetSoftwareObjectById(incompleteObjectFromLdap.ID);
                  }
                  //more than one object was returned -&gt; check revisions
              default:
                  {
                      List&lt;MdsObject&gt; ListReturnedObjects = new List&lt;MdsObject&gt;();
  
                      for (int i = 1; i &lt;= getObjectListReply.ObjectList.Length; i++)
                      {
                          MdsObject incompleteObjectFromLdap = getObjectListReply.ObjectList[i-1];
                          ListReturnedObjects.Add(GetSoftwareObjectById(incompleteObjectFromLdap.ID));
                      }
  
                      **Here I need to filter the objects**
  
                      throw new ApplicationException("GetSoftwareObjectByName failed. Software name '" + sPackageName + "' is not unique!");
                  }
          }
      }
  </code></pre>