Reputation: 547
I have a list of 2d arrays. Now I want to sort my list *based on* only 1st element of my array - not the second element. I wrote the code as following:
List<double[,]> lsResultsOfEq = new List<double[,]>();
double[,] resultOfEqConv;
for (int i = 0; i < n; i++)
{
resultOfEq = a*b*c;
//add value and index
resultOfEqConv = new double[1, 2];
resultOfEqConv[0, 0] = (double)resultOfEq[0, 0];
resultOfEqConv[0, 1] = i;
lsResultsOfEq.Add(resultOfEqConv);
}
Now when I use the sort function I get the error "Failed to compare two elements in the array" how should I set my sortlist that only do the sorting based on first elemen of array.
Upvotes: 3
Views: 2334
Reputation: 38598
Try using OrderBy
method from linq, for sample:
include the namespace:
using System.Linq;
and try this:
var orderResult = lsResultsOfEq.OrderBy(x => x[0, 0]).ToList();
Upvotes: 4