日期:2014-05-17 浏览次数:20462 次
int[]{5,9,3,2,0,8,7,1,9};
int[] arr = { 5, 9, 3, 2, 0, 8, 7, 1, 9 }; List<int> list = arr.OrderByDescending(x => x).Take(5).ToList<int>(); arr.ToList().ForEach(x => { if (list.Contains(x))Console.WriteLine(x); });
------解决方案--------------------
int[] int_array=new int[]{5,9,3,2,0,8,7,1,9}; int_array=int_array.Select((a, i) => new { index = i, value = a }).OrderByDescending(a => a.value).Take(5).OrderBy(a => a.index).Select(a=>a.value).ToArray(); /* [0] 5 int [1] 9 int [2] 8 int [3] 7 int [4] 9 int */