public List<int> CheckHash(List<int> data)
        {
            Hashtable hasttable = new Hashtable();
}
检查 data数组中的重复数 最后输出所有重复数及个数 按照先后顺序
如3 1 5 3 3 1
输出 3 3 3 1 1

解决方案 »

  1.   

    public List<int> CheckHash(List<int> data)
    {
        return (from x in data group x by x into g select g).Where(g => g.Count() > 1).SelectMany(x => x).ToList();
    }
      

  2.   

    测试了下,没问题
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine(string.Join(" ", CheckHash(new List<int>() { 3, 1, 5, 3, 3, 1 })));
            }
            static List<int> CheckHash(List<int> data)
            {
                return (from x in data group x by x into g select g).Where(g => g.Count() > 1).SelectMany(x => x).ToList();
            }
        }
    }3 3 3 1 1
    Press any key to continue . . .
      

  3.   

    我知道没问题 但是 能用属性和方法写吗?这么写我看不懂 尤其是=>这是什么母达表达式 我不懂,
     Hashtable hasttable = new Hashtable();
    用hasttable的属性方法 写一次  我好能在msdn中更好的了解 谢谢了
      

  4.   

    本帖最后由 caozhy 于 2011-09-06 20:45:53 编辑
      

  5.   

    你这个我明白了 就是在本List里查找 但是它和key和value的体现在什么地方 我还没有发现 顺便还学习了下linq 真是多谢你了