求个算法
   ArrayList test = new ArrayList(1,1,2,2,1,5,6,8,6,);
这个数组里面有多少个1,多少个2,多少个6等...
数组的数据是不一定的。

解决方案 »

  1.   

    var result = (from x in test group x by x.ToString() into groups).Select(x => new { key = x.Key, value = x.Count });
    foreach (var i in result)
    {
        Console.WriteLine(i.key.ToString() + "有" + i.value.ToString() + "个");
    }
      

  2.   


    Hashtable ht=new Hashtable();
    for(int i=0;i<test.Length;++i)
    {
      if(!ht.ContainKey(test.get(i)))
      {
         ht.Add(test.get(i),1);
      }
      else
      {
         ht[test.get(i)]+=1;
      }
    }
    //然后遍历ht输出答案
      

  3.   

    报错了,但是不知道怎么改,不懂Linq
     错误 1 查询正文必须以 Select 子句或 Group 子句结尾 C:\Users\ChenLelI\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs 15 77 ConsoleApplication1
      

  4.   

    本帖最后由 caozhy 于 2011-05-31 19:40:30 编辑
      

  5.   

    大哥,还是报错呀,
    错误 1 找不到源类型“System.Collections.ArrayList”的查询模式的实现。找不到“GroupBy”。请考虑显式指定范围变量“x”的类型。 C:\Users\ChenLelI\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs 16 37 ConsoleApplication1
      

  6.   

    谢谢,可以了,回去该研究Linq了
      

  7.   

    都能用上linq了,为什么还要用ArrayList来装值类型的的元素呢……
      

  8.   

    94试了下,ArrayList 不能支持 LINQ 扩展方法