如何避免从数组中选择重复元素 [英] How to avoid selecting duplicate element from an array
本文介绍了如何避免从数组中选择重复元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你能建议任何避免从C#中的数组中挑选重复元素的方法吗?
Can you suggest any method to avoid picking of a duplicate element from an array in C#?
推荐答案
使用Distinct
扩展方法:
Hi,
Use theDistinct
extension method:
int[] array = new int[7] { 7, 8, 1, 9, 10, 7, 1 };
array = array.Distinct().ToArray();
希望这会有所帮助。
Hope this helps.
你可以实现你在LINQ的帮助下瞄准:
You can achive you aim with help of LINQ:
string[] testArray=new string [3]{ "Data","Data ","One"};
var arrayWithout=testArray.Distinct().ToArray();
这篇关于如何避免从数组中选择重复元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文