从数组中删除重复项的算法. [英] Algorithm to remove duplicates from an array.
本文介绍了从数组中删除重复项的算法.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从数组中删除重复项的算法.
范例:
国家名称重复的数组,如
(印度",巴基斯坦",美国,德国",巴基斯坦",英格兰",爱尔兰",印度").
(可以开发Windows窗体来演示这一点).
Algorithm to remove duplicates from an array.
Example :
array having duplicate country names Like
(‘India’,’Pakistan’,United states ofAmerica’,’Germany’,’Pakistan’,’England’,’Ireland’,’India’).
(A windows form can be developed to demonstrate this)
推荐答案
我认为这不是您的作业.
无论如何,我都不会直接给出代码,请在此处查看详细信息/选项
http://stackoverflow.com/questions/9673/remove-duplicates-from-array [ ^ ]
I suppose this is not your homework.
Any way I wont give direct code, check out the details/options here
http://stackoverflow.com/questions/9673/remove-duplicates-from-array[^]
IEnumerable接口的不同扩展方法可用于此目的.
Distinct extension method of IEnumerable Interface can be used for this purpose.
string[] Countries = {
"India", "Pakistan", "United States of America", "Germany",
"Pakistan", "England", "Ireland", "India"};
var query = Countries.Distinct();
var distinctCountries = query.ToArray();
可以提供IEqualityComparer<T>
参数来控制字符串的比较.
The IEqualityComparer<T>
parameter can be supplied for controlling comparison of strings.
这篇关于从数组中删除重复项的算法.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文