Given the following values in order :
011124
01112
011123
1905
How could I use Linq to sort this:
List<string> values = new List<string>() { "011124", "01112", "011123", "1905" };
.. so it is effectively this:
List<string> values = new List<string>() { "011124", "011123", "01112", "1905" };
(updated: added '1905' as the previous demo would have sorted easily with an int sort -- sorry for the confusion)
Convert.ToInt32()as this returns a 0 on non-convertible numbers whereint.Parse()would throw an exception. Both are good, and truly do appreciate everyones input. I have voted everyone up as well :)Convert.ToInt32will internally callint.Parse, which will throw an exception if it is a non-convertible string. Only if thestringis null, then it will return 0.