int[] a = { 3, 4, 3, 8, 9, 22, 44, 1, 5, 66, 11, 16, 21, 22, 2, 55, 99, 26, 29, 11, 3, 22, 62, 69, 72, 79, 22 };如何統計有那些數字是重複?
還有把重複的資料剔除?
還有把重複的資料剔除?
解决方案 »
- wcf--服务端主动 向---------------------- 某个客户端推送消息--------------
- 关于MVC link:fatal error link1104 :connot open file ' LIBCMT.lib'错误
- Website項目與Web Application Project項目有什麼區別(謝謝)
- 求助C#(Winform)获取地址栏后面的参数
- [WinForm]关于透明窗体的问题
- 看清楚再投票!美国CNN网站现在(2005-4-17)的问题变成了:中国反日的情结是否正确?选yes啊!!!
- 请问C#中怎么进行复数运算
- sharepoint 中建立一个更改用户密码的WebPart。急!!!非常急的!!!
- csproj文件怎么没有啊?????
- C#调用命令行时(cmd.exe),如何让命令行打开的目录为执行程序的目录?
- 不能直接定义键盘捕获事件
- VS2010 RDLC报表分组小计,硬是做不出来,求助
Console.WriteLine("重复的数");
a.GroupBy(t => t).Where(t => t.Count() > 1).Select(t => t.Key).ToList().ForEach(t => Console.WriteLine(t));
//去除重复的数
a = a.Distinct().ToArray();
int[] a = { 3, 4, 3, 8, 9, 22, 44, 1, 5, 66, 11, 16, 21, 22, 2, 55, 99, 26, 29, 11, 3, 22, 62, 69, 72, 79, 22 }; //Lambda表达式
var result = a.GroupBy(c => c).Where(d => d.Count() > 1).OrderBy(c=>c.Key); //LINQ
var result1 = from u in a
group u by u into temp
where temp.Count()>1
orderby temp.Key
select new
{
temp.Key,
Count = temp.Count()
};
foreach (var item in result)
Console.WriteLine(item.Key + " " + "Count=" + item.Count()); foreach (var item in result1)
Console.WriteLine(item.Key + " " + "Count=" + item.Count);