Asp.Net C#4.0新特性:distinct去掉集合重复数据
2011-06-18 03:47
363 查看
Asp.Net C# 4.0中用distinct去掉集合重复数据(非SQL),Distinct大家都知道干嘛的,常用于SQL查询时去掉重复数据。非常好用吧。嘿嘿,那么如果是集合中的重复数据怎么办呢?只能费尽心思想办法循环、遍历检测。下面我介绍一个 C# 4.0 中一个方法,对值进行比较返回序列中的非重复元素。
C# 4.0 中 Distinct 语法
C# 4.0 中 Distinct 语法
public static IEnumerable<TSource> Distinct<TSource>(
this IEnumerable<TSource> source
)
C# 4.0 中 Distinct Demo
protected void Page_Load(object sender, EventArgs e)
{
List<String> strMaoBlogList = new List<String>();
strMaoBlogList.Add("a");
strMaoBlogList.Add("a");
strMaoBlogList.Add("b");
strMaoBlogList.Add("b");
strMaoBlogList.Add("c");
strMaoBlogList.Add("c");
String _maoBlog = String.Empty;
IEnumerable<String> distinctList = strMaoBlogList.Distinct();
foreach (String str in distinctList)
_maoBlog += str + " ";
Response.Write(_maoBlog.Trim());
}
MSDN 示例
List<int> ages = new List<int>
{ 21, 46, 46, 55, 17, 21, 55, 55 };
IEnumerable<int> distinctAges = ages.Distinct();
outputBlock.Text += "Distinct ages:" + "\n"; foreach (int age in distinctAges)
{
outputBlock.Text += age + "\n";
}
/*
This code produces the following output: Distinct ages: 21 46 55 17
*/[/code]
相关文章推荐
- C#去掉list集合中的重复数据
- mysql 的 distinct 去掉重复的数据
- (散分,学习)突然发现一个比较好的去掉集合中重复数据的算法
- 集合中去掉重复数据的方法
- distinct和group by 去掉重复数据分析
- distinct和group by 去掉重复数据分析
- List集合筛选数据去掉重复,含有数据重复次数(JAVAAndroid)
- SQL DISTINCT去掉重复的数据统计方法
- distinct 去重复查询——两个表join 连接,去掉重复的数据
- 两个List集合去掉重复数据
- set集合去掉重复数据
- 使用C语言去掉字符串集合重复元素
- List或者arraylist去掉重复数据(对象也可以)
- 利用SQL Server 2005特性删除表中重复数据
- 将集合中的重复元素去掉
- mysql 用sql 语句去掉某个字段重复值数据的方法
- java两个ArrayList合并,并且去掉重复数据的算法
- android List去掉重复数据
- mysql去掉重复数据
- 利用java集合Set、Map、List等的特性,分类统计各组数据的数量