I have a list similar to this:
List<Item> myList = new List<myObj>();
myList.Add(new Item({ val = A1, text="A1 - Alpha1"});
myList.Add(new Item({ val = A2, text="A2 - Alpha2"});
myList.Add(new Item({ val = A10, text="A10 - Alpha10"});
myList.Add(new Item({ val = A, text="A - Alpha"});
I'm looking to order this list alphabetically by their values so:
"A", "A1", "A2", "A10"
would be the desired order but I end up getting:
"A", "A1", "A10", "A2"
when using Linq's .OrderBy(x=>x.val)
method.
I have tried some answers on Stack Overflow using custom ordering but these answers don't account for a mixture of values where it may or may not contain a numeric entry. Some of these orders are involving conversions to ints which won't satisfy all the values in my list.
How would it be possible to obtain the correct ordered result?