List对象中有几个长度相同的整型数组,如果再在List中循环找出这些数组中对应位置上的最大value,简单例子说明:假如有三个数组如下:int[] a1 = new int[] { 3, 10, 5, 0 };
int[] a2 = new int[] { 1, 9, 7, 6 };
int[] a3 = new int[] { 5, 3, 5, 8 };比较后得到新数组对象 ax = new int[]{5, 9, 10, 8};请问如何在遍历整个List情形下中实现呢?我的平台是VS2005,不能用LINQ实现。thanks

解决方案 »

  1.   

    你说你这个人,之前的帖子都有答案了,怎么还问呢,好几个都可以用在2005下            int[] a1 = new int[] { 3, 6, 5, 0 };
                int[] a2 = new int[] { 1, 9, 7, 6 };
                int[] a3 = new int[] { 5, 3, 5, 8 };
                int[] a4 = new int[4];
                int tmp;
                for (int i = 0; i < 4; i++)
                {
                    tmp = a1[i] > a2[i] ? a1[i] : a2[i];
                    tmp = tmp > a3[i] ? tmp : a3[i];
                    a4[i] = tmp;
                }
      

  2.   

    我这里的List需要循环的,针对List循环的话当如何处理呢?谢你了
      

  3.   


    int[] a1 = new int[] { 3, 6, 5, 0 };
                int[] a2 = new int[] { 1, 9, 7, 6 };
                int[] a3 = new int[] { 5, 3, 5, 8 };
                int[] a4 = new int[4];            List<int[]> list = new List<int[]>() { a1, a2, a3, a4 };
                
                for (int i = 0; i < list.Count; i++)
                {
                    int temp = 0;
                    for (int j = 0; j < list[i].Length; j++)
                    {
                        temp = list[j][i] > temp ? list[j][i] : temp;
                    }
                    list[list.Count-1][i] = temp;
                }
    经过测试了,应该可以吧?