如一组数中有1、4、5、4、3、5、1
结果重复的数为:1、4、5

解决方案 »

  1.   

     int[] int_array = new int[] {1,4,5,4,3,5,1 };
                int[] repeat_array = int_array.GroupBy(a=>a).Where(a=>a.Count()>1).Select(a=>a.Key).ToArray();
                /*
                [0] 1 int
        [1] 4 int
        [2] 5 int             */
      

  2.   


                int[] array = new int[] { 1, 4, 5, 4, 3, 5, 1 };
                int[] newArray = (from i in array
                        group i by i into grouped
                        where grouped.Count() > 1
                        select grouped.Key).ToArray();