sorting - C# List<string> sort issue -
i have list looks like:
list<string> newlist = new list<string>() { "10s", "xs", "80", "5s", "160", "40s", "80s", "std", "40", "xxs" };
and want sort
- { "40", "80", "160", "5s", "10s", "40s", "80s", "std", "xs", "xxs" };
how should it? hope can me on issue, lot!
list<string> list = new list<string>() { "10s", "xs", "80", "5s", "160", "40s", "80s", "std", "40", "xxs" }; // filter out numbers: int temp; var newlist = (from item in list int.tryparse(item, out temp) select item).tolist(); // sort number , string: newlist = newlist.select(x => int.parse(x)).orderby(x => x).select(x => x.tostring()).tolist(); // sort rest string: var second = list.except(newlist).orderby(x => x).tolist(); // merge 2 newlist.addrange(second);
newlist : { "40", "80", "160", "5s", "10s", "40s", "80s", "std", "xs", "xxs" };
Comments
Post a Comment