My Code looks like this :
Collection<NameValueCollection> optionInfoCollection = ....
List<NameValueCollection> optionInfoList = new List<NameValueCollection>();
optionInfoList = optionInfoCollection.ToList();
if(_isAlphabeticalSoting)
Sort optionInfoList
I tried optionInfoList.Sort() but it is not working.
Using the sort method and lambda expressions, it is really easy.
The above example shows how to sort by the Name property of your object type, assuming Name is of type string.
You need to set up a comparer that tells Sort() how to arrange the items.
Check out List.Sort Method (IComparer) for an example of how to do this...
If you just want
Sort()
to work, then you'll need to implementIComparable
orIComparable<T>
in the class.If you don't mind creating a new list, you can use the
OrderBy
/ToList
LINQ extension methods. If you want to sort the existing list with simpler syntax, you can add a few extension methods, enabling:For example: