Reputation: 99
Ive got a list which contains data separated by a comma. Its part of a C# ASP.net project. so the data in my list looks like this:
10323323,102,99-11
13223,101,00-10
23234323223,178,00-99
I want to re-arrange the list so that the value in the middle arranges the items in the lost in descending order so id end up with a list that looks like.
13223,101,00-10
10323323,102,99-11
23234323223,178,00-99
Upvotes: 0
Views: 162
Reputation: 3056
If your strings are always 3 values comma-separated, and the middle value is a string representation of an integer
, something like this should do the job:
List<string> list = new List<string>()
{
"10323323,102,99-11",
"13223,101,00-10",
"23234323223,178,00-99"
};
list = list.OrderBy(x => Convert.ToInt32(x.Split(',')[1])).ToList();
Upvotes: 3