I have an ArrayList that contains,
[0] = \"1\"
[1] = \"10\"
[2] = \"2\"
[3] = \"15\"
[4] = \"17\"
[5] = \"5\"
[6] = \"6\"
[7] = \"27\"
[8] = \"8\"
[9] = \"9\"
>
If you can be sure the list contains only strings that can be transformed to integers, then with the IEnumerable
var sortedList = list.OrderBy(item => int.Parse(item));
If you're using an ArrayList
instead of a List
(boo!), you'll need to Cast
first:
var sortedList = list.Cast().OrderBy(item => int.Parse(item));
You can also define your own comparer as JaredPar noted, but IMO that's a lot of work for something that's already implemented. However, it's more efficient.