天气很热,所以我的大脑不能很好地工作。用 LINQ 对此进行排序的最佳方法是什么?请注意,排序基于“C”进行,但适用于“M”
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Compare
{
public class M
{
public IList<C> Columns = new List<C>();
}
public class C
{
public bool SortByMe { get; set; }
public string Guid { get; set; }
}
class Program
{
static void Main(string[] args)
{
IList<M> list = new List<M>();
M one = new M();
one.Columns.Add(new C()
{
SortByMe = true,
Guid = "5"
});
one.Columns.Add(new C()
{
});
one.Columns.Add(new C()
{
});
M two = new M();
two.Columns.Add(new C()
{
});
two.Columns.Add(new C()
{
SortByMe = true,
Guid = "2"
});
two.Columns.Add(new C()
{
});
M three = new M();
three.Columns.Add(new C()
{
});
three.Columns.Add(new C()
{
SortByMe = true,
Guid = "100"
});
three.Columns.Add(new C()
{
});
list.Add(one);
list.Add(two);
list.Add(three);
//Then sort the M by the occurrence of a C with SortByMe true.
}
}
}