如 一组数:1,2,3,4,5,1,2,3 ...,n;
如何得到这组数中重复数据;

解决方案 »

  1.   

    把数据存入数据库,用SQL语句分析
      

  2.   

    循环遍历,若相等,break并保存
      

  3.   

    int[] arr = {1,2,.....,n};var g=from a in arr
          group a by a into c
          where c.count()>1
          select c
    试试LINQ
      

  4.   


        Sub Main()        Dim a = {1, 2, 3, 4, 5, 1, 2, 3}        Dim b = From o In a
                    Group o By o Into Count()
                    Where Count > 1        For Each o In b
                Console.WriteLine(o.o)
            Next
        End Sub
      

  5.   

           这个执行效率不高,但是结果应该是你想要的。还有很多方法,你在想想吧!
            private void Compare()
            {
                string str = null;
                int[] arr1 = { 1, 2, 5, 4, 7, 8, 5,1, 9 };
                for (int i = 0; i < arr1.Length; i++)
                {
                    for (int j = i+1; j < arr1.Length; j++)
                    {
                        if (arr1[i] == arr1[j])
                        {
                            str += arr1[i].ToString()+" ";
                        }
                        
                    }
                }
                MessageBox.Show(str);
            }
      

  6.   


                    string[] arr = new string[] { "12345678", "12345678", "123456789" }; 
                     //初始化Dictionary对象
                        SortedDictionary<string, int> freq = new SortedDictionary<string, int>();                    foreach (string dicstr in arr)
                        {
                            if (!string.IsNullOrEmpty(dicstr.Trim()))
                            {
                                if (freq.ContainsKey(dicstr.Trim()))
                                {
                                    freq[dicstr.Trim()]++;
                                }
                                else
                                {
                                    freq.Add(dicstr.Trim(), 1);
                                }
                            }
                        }
      

  7.   

    改变成LZ想要的int[] intArray = {1,2,3,4,5,1,2,3};
    //List用于存储从数组里取出来的不相同的元素
    List<int> listInt = new List<int>();
    foreach (int eachInt in intArray) 
    {
    if (!listInt.Contains(eachInt))
    listInt.Add(eachInt);
    }
    //最后从List里取出各个数字进行操作         
    foreach (int eachInt in listInt)
    {
    Console.Write(eachInt); //打印每个数字
    }
      

  8.   

       int [] a={1,1,3,2,4,5,4,7,8,9,4,};
               
                List<int> list = new List<int>();
                for (int i = 0; i < a.Length;i++ ) 
                list.Add(a[i]);
                for (int k = 0; k < list.Count;k++ )
                {
                    if (list.Contains(a[k]))
                    {
                        list.Remove(a[k]);
                        if (list.Contains(a[k]))
                            list.Add(a[k]);
                    }
                }试试
      

  9.   

                int[] arr = { 1, 2, 3, 4, 5, 1, 2, 3 };
                var linq = from a in arr group a by a into g where g.Count() > 1 select g;
                foreach (var l in linq)
                    Console.WriteLine(l.Key);
      

  10.   

     int[] str = {1,2,3,4,5,6,7,8,2,5,6,8 };
                var s = from n in str
                        group n by n into c
                        where c.Count() > 1
                        select c;
                
               foreach (var t in s) //遍历对象
                {
                    foreach (var tt in t)
                    {
                        Response.Write(tt.ToString() + "<br/>"); //输出查询结果
                    }
                }这是linq的方式,也可以用楼上的方式。
      

  11.   

     int[] a = { 1,2,3,4,5,1,2,3,44};            a.ToLookup(v => v).Where(v => v.Count() > 1).Select(v => v.Key);