本帖最后由 yangxic 于 2009-07-17 18:41:23 编辑

解决方案 »

  1.   

    int[] a = new int[] { 3, 1, 2, 1, 3, 3, 4, 5, 6, 5 };
                ArrayList _ArrayList = new ArrayList();
                for (int i = 0; i < a.Length; i++)
                {
                    int b = a[i];
                    int c = 0;
                    for (int j = 0; j < a.Length; j++)
                    {
                        if (b == a[j])
                            c++;
                        if (c == 2)
                        {
                            _ArrayList.Add(a[i]);
                            break;
                        }
                    }
                }            string _str = string.Empty;
                for (int i = 0; i < _ArrayList.Count; i++)
                {
                    _str += _ArrayList[i].ToString();
                }            MessageBox.Show(_str);
      

  2.   

    数据量大可以使用ado.net,把数据先导入数据表里面,在通过DataTable的DefaultView的ToTable方法具体可以参考这个帖子:
    http://topic.csdn.net/u/20090629/09/87284117-494a-47c2-97a8-322821c16cc3.html
      

  3.   

    try...
     static void Main(string[] args)
            {            
                Int32[] array=new Int32[]{3,1,2,1,3,3,4,5,6,5};
                Dictionary<Int32, Int32> dic = new Dictionary<int,int>();
                for (int i = 0; i < array.Length; i++)
                {
                    if (!dic.ContainsKey(array[i]))
                        dic.Add(array[i], 1);
                    else
                        dic[array[i]]++;
                }
                for (int i = 0; i < array.Length; i++)
                {
                    if(dic[array[i]]>1)
                        Console.WriteLine(array[i]);
                }                  }
      

  4.   

    下面输出代码已通过验证 输出结果为 321456
    private void button1_Click(object sender, EventArgs e)
            {
                int[] a = new int[] { 3, 1, 2, 1, 3, 3, 4, 5, 6, 5 };
                List<int> Lt = new List<int>();
                ArrayList mArrayList = new ArrayList();
                bool tag = true; //设置是否存在相同值的标志,存在则为false            for (int i = 0; i < a.Length; i++)
                {                if (Lt.Count > 0)
                    {
                        foreach (int b in Lt)
                        {
                            if (b == a[i])
                            {
                                tag = false;
                            }
                        }                    if (tag)
                        {
                            mArrayList.Add(a[i]);
                        }
                        if (Lt.Count != mArrayList.Count)
                        {
                            Lt.Add(Convert.ToInt32(mArrayList[mArrayList.Count - 1].ToString()));
                        }
                        tag = true; //执行一次完后重新置为true以便再次进行判断                }
                    else
                    {
                        Lt.Add(a[i]);
                        mArrayList.Add(a[i]);
                    }
                }            //显示
                string str = string.Empty;
                for (int i = 0; i < Lt.Count; i++)
                {
                    str += Lt[i].ToString();
                }            MessageBox.Show(str);
            }