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.ListobjectList = new System.Collections.Generic.List (objectArray);
Then I sorted the list:
objectList.Sort(delegate(CustomObject o1, CustomObject o2)
{
return o1.ObjectName.CompareTo(o2.ObjectName);
});
Post Tags: code