Convert an Array of Objects to a List, Then Sort the List

I recently had to build a page that consumed a web service returning data in an array of custom objects. The array was sorted by ID, while I needed to display it sorted alphabetically by name.

First, I had to convert the array of objects to a list:

CustomObject[] objectArray;

objectArray = fancyWebServiceFunction();

System.Collections.Generic.List objectList = new System.Collections.Generic.List(objectArray);

Then I sorted the list:

  objectList.Sort(delegate(CustomObject o1, CustomObject o2)
     return o1.ObjectName.CompareTo(o2.ObjectName);

Subscribe to comments Comment | Trackback |
Post Tags:

Browse Timeline

Add a Comment

You must be logged in to post a comment.

© Copyright 2009-2010 Alpha Papa Hotel . Thanks for visiting!