如何从 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屋!
查看全文