最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
asp.net 获取数组中重复数据代码
时间:2010-07-30 编辑:简简单单 来源:一聚教程网
asp教程.net 获取数组中重复数据代码
下面提供了五款不同方法的取出数据中重复的数据并统计重复的次数。
dictionarydic = new dictionary();
int[] arr = new int[] { 1, 5, 2, 6, 7, 1, 5, 4, 1, 6, 8, 7, 6 };
foreach(int i in arr)
{
try
{
dic.add(i, i);
}
catch(exception err)
{
//.... ...
}
}
//方法二
int[] arr = new int[] { 1, 5, 2, 6, 7, 1, 5, 4, 1, 6, 8, 7, 6 };
int n = arr.length - arr.distinct().count();
//方法三
int[] ary = new int[] { 1, 3, 3, 4, 5, 4 };
var q = from x in ary
group x by x into y
select {y.key,y.count()};
//方法四
int[] arr = new int[] { 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7 };
var gs = arr.groupby(i => i).orderby(i => i.count());
console.writeline(gs.lastordefault().toarray()[0]);
//方法五
int[] arr = { 1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 5 };
var linqer =
from a in arr
group arr by a into b
orderby b.count()
select new
{
b.key,
count = b.count()
};
foreach (var i in linqer)
{
console.writeline("{0}出现{1}次", i.key, i.count);
}
-
下一个: asp.net如何连接数据库
相关文章
- C#复制数组的两种方式及效率比较解读 10-24
- ASP.NET Identity用法解析 10-24
- ASP.NET MVC使用Identity增删改查用户介绍 10-24
- C语言中atoi函数模拟实现介绍 10-18
- .Net反向代理组件Yarp用法介绍 10-10
- .NET使用YARP通过编码方式配置域名转发实现反向代理教程 10-10