求个算法 关于ArrayList的 求个算法 ArrayList test = new ArrayList(1,1,2,2,1,5,6,8,6,);这个数组里面有多少个1,多少个2,多少个6等...数组的数据是不一定的。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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() + "个");} 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输出答案 报错了,但是不知道怎么改,不懂Linq 错误 1 查询正文必须以 Select 子句或 Group 子句结尾 C:\Users\ChenLelI\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs 15 77 ConsoleApplication1 本帖最后由 caozhy 于 2011-05-31 19:40:30 编辑 大哥,还是报错呀,错误 1 找不到源类型“System.Collections.ArrayList”的查询模式的实现。找不到“GroupBy”。请考虑显式指定范围变量“x”的类型。 C:\Users\ChenLelI\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs 16 37 ConsoleApplication1 谢谢,可以了,回去该研究Linq了 都能用上linq了,为什么还要用ArrayList来装值类型的的元素呢…… 94试了下,ArrayList 不能支持 LINQ 扩展方法 连接 access 2010 谁能帮我写个网站的评论留言的模版 debug assertion failed 急求,查询EXCEL的时候,使用cast函数转换出错 如何在VS中,用C#代码显示打开文件的窗口?? Response.Cookies.Add()和方法Response.AppendCookie()有什么区别? 我在代码使用一个Button1_Click,在我的xp系统完全可以提交增加,但是我把系统移到2003上点击就没有任何反映,为什么 关于单元测试(NUnit.org) 关于一小段c#代码的不明白…… 请问怎样在datagrid中实现分页? 求助!binaryWrite写进的int32,binaryReader读不出来 为什么这样写不对
foreach (var i in result)
{
Console.WriteLine(i.key.ToString() + "有" + i.value.ToString() + "个");
}
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输出答案
错误 1 查询正文必须以 Select 子句或 Group 子句结尾 C:\Users\ChenLelI\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs 15 77 ConsoleApplication1
错误 1 找不到源类型“System.Collections.ArrayList”的查询模式的实现。找不到“GroupBy”。请考虑显式指定范围变量“x”的类型。 C:\Users\ChenLelI\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs 16 37 ConsoleApplication1