Using C# what is the best way to sort a List numerically? my list has items 5,7,3 and I would like them sorted 3,5,7. I know some longer ways, but I would imagine linq has a quicker way?
sorry this was end of day, my mind is else where it worked, didn't see it change the first time:(
There's no need for LINQ here, just call Sort:
list.Sort();
Example code:
List<int> list = new List<int> { 5, 7, 3 }; list.Sort(); foreach (int x in list) { Console.WriteLine(x); }
Result:
3 5 7
Keeping it simple is the key.
Try Below.
var values = new int[5,7,3]; values = values.OrderBy(p => p).ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With