两个方案
//逐个比较,找出最大的那个数组
static void Main(string[] args)
{
//测试数据
int[] num0 = { 5, 8, 6 };
int[] num1 = { 12, 9, 1 };
int[] num2 = { 3, 7, 2 };
int[] num3 = { 12, 9, 3 };
List<int[]> myList = new List<int[]>() {
num0,num1,num2,num3
};
//方法1(Lambda排序)
int[] o = myList.OrderByDescending(a => a[0]).ThenByDescending(a => a[1]).ThenByDescending(a => a[2]).FirstOrDefault();
Console.WriteLine("{0},{1},{2}", o[0], o[1], o[2]);
//方法2(匿名比较器)
myList.Sort((int[] a, int[] b) =>
{
for (int i = 0; i < a.Length; i++)
{
if (a[i] < b[i])
return 1;
if (a[i] == b[i])
continue;
if (a[i] > b[i])
return -1;
}
return 1;
});
var q = myList[0];
Console.WriteLine("{0},{1},{2}",q[0],q[1],q[2]);
Console.ReadLine();
}