日期:2014-05-18 浏览次数:20723 次
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 */
------解决方案--------------------
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();