I have a Classes like this:
Public class ClassA
{
public Class1[] Class1{ get; set; }
}
Public class Class1
{
public Class2[] Class2{ get; set; }
public double TotalTime1 { get; set; }
}
Public class Class2
{
public double Count{ get; set; }
}
here i am trying to sort the ClassA like below:
IList<Class1> Data = new List<Class1>();
Data = ClassA.Class1.OrderBy(m => m.Class2.OrderBy(k => k.Count)).ToList();
Please how can i sort the Class1 using the Count in Class2.
You are trying to sort on the result of the inner
OrderBy, which is a sequence ofClass2objects and this doesn’t implementIComparable.You have to sort on a single value, not a sequence. If you for example want to sort on the largest
Countvalue in eachClass1object, use theMaxmethod:There are also other plausible ways that you may want to produce a value from the
Class2array, like for example using theMin,Sum,AverageorFirstmethod.