答案 0 :(得分:2)
答案 1 :(得分:2)
您应该可以使用LINQ和IEnumerable<double>
的自定义IComparer来完成此操作。
public class EnumerableDoubleComparer : IComparer<IEnumerable<double>>
{
public int Compare( IEnumerable<double> a, IEnumerable<double> b )
{
var counts = a.Select( (k,i) => new { Value = k, Index = i } )
.Join( b.Select( (k,i) => new { Value = k, Index = i } ),
outer => outer.Index,
inner => inner.Index,
(outer,inner) => outer.Value > inner.Value
? "A"
: (inner.Value > outer.Value
? "B"
: "" ) )
.GroupBy( listID => listID )
.Select( g => new { g.Key, Count = g.Count() } );
// you could also use SingleOrDefault on the collection and check for null
var aCount = counts.Where( c => c.Key == "A" )
.Select( c => c.Count )
.SingleOrDefault();
var bCount = counts.Where( c => c.Key == "B" )
.Select( c => c.Count )
.SingleOrDefault();
return aCount - bCount;
}
}
用作:
var a = new double[] { 1, 1 };
var b = new double[] { 2, 2 };
var c = new double[] { 3, 3 };
var lists = new List<IEnumerable<double>> { a, c, b };
var ordered = lists.OrderByDescending( l => l, new EnumerableDoubleComparer() );
答案 2 :(得分:1)
答案 3 :(得分:1)
答案 4 :(得分:1)
答案 5 :(得分:1)
答案 6 :(得分:1)
答案 7 :(得分:1)
答案 8 :(得分:0)