var orderedList = your_list.OrderBy(r => r.subitem);
And also you can use from your own sorting method (I think don't required in your case)
usage :
var orderedList = your_list.OrderBy(r => GetOrder(r.subitem));
sample method :
Public Static int GetOrder(string _arg)
{
switch (_arg)
{
case 'Section One':
return 1;
case 'Section Two':
return 2;
case 'Section Three':
return 3;
.
.
.
default:
return int.MaxValue;
}
}
-------------Edit : Added Example Project --------------------
Just Use from this code :
var list = List_unsort.OrderBy(x => x.number);
Example Project :
public static void Main()
{
Console.WriteLine("Start Work ...\r\n");
Create_list();
Sort_list();
Console.WriteLine("\r\nFinish.");
}
private static List<custom_item> List_unsort = new List<custom_item>();
private class custom_item
{
public int id { get; set; }
public string name { get; set; }
public double number { get; set; }
}
private static void Create_list()
{
Random rnd = new Random();
Console.WriteLine("Unsort List : ");
for (int i = 0; i < 10; i++)
{
custom_item item = new custom_item();
item.name = i.ToString();
item.id = i;
double rnd_num = rnd.NextDouble();
item.number = rnd_num;
Console.WriteLine("ID : " + item.id + ", number : " + item.number);
List_unsort.Add(item);
}
Console.WriteLine("\r\n--------------------\r\n");
}
private static void Sort_list()
{
var list = List_unsort.OrderBy(x => x.number);
Console.WriteLine("Sort List : ");
foreach (var item in list)
{
Console.WriteLine("ID : " + item.id + ", number : " + item.number);
}
}
and Output :
Start Work ...
Unsort List : ID : 0, number : 0.333175984366413
ID : 1, number : 0.886352685227223
ID : 2, number : 0.633657003582295
ID : 3, number : 0.319651832021611
ID : 4, number : 0.340439343983512
ID : 5, number : 0.476074807567557
ID : 6, number : 0.664470672451179
ID : 7, number : 0.14823883685667
ID : 8, number : 0.375242880254631
ID : 9, number : 0.186346486763259
Sort List :
ID : 7, number : 0.14823883685667
ID : 9, number : 0.186346486763259
ID : 3, number : 0.319651832021611
ID : 0, number : 0.333175984366413
ID : 4, number : 0.340439343983512
ID : 8, number : 0.375242880254631
ID : 5, number : 0.476074807567557
ID : 2, number : 0.633657003582295
ID : 6, number : 0.664470672451179
ID : 1, number : 0.886352685227223
Finish.
Link for Compile and test project :
http://rextester.com/NHFTU85530
OR
https://dotnetfiddle.net/GWWNgb