如何从C#数组中删除重复项? [英] How do I remove duplicates from a C# array?
本文介绍了如何从C#数组中删除重复项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在使用C#中的string[]
数组,该数组从函数调用中返回.我可以转换为Generic
集合,但我想知道是否有更好的方法可以做到这一点,可能是通过使用临时数组.
I have been working with a string[]
array in C# that gets returned from a function call. I could possibly cast to a Generic
collection, but I was wondering if there was a better way to do it, possibly by using a temp array.
从C#数组中删除重复项的最佳方法是什么?
推荐答案
您可以使用LINQ查询来做到这一点:
You could possibly use a LINQ query to do this:
int[] s = { 1, 2, 3, 3, 4};
int[] q = s.Distinct().ToArray();
这篇关于如何从C#数组中删除重复项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文