.net - 如何在 .net 中获取数组的唯一值?

标签 .net arrays unique

说我有这个数组:
MyArray(0)="aaa"
MyArray(1)="bbb"
MyArray(2)="aaa"

是否有一个 .net 函数可以给我唯一的值?我想要这样的东西作为函数的输出:
OutputArray(0)="aaa"
OutputArray(1)="bbb"

最佳答案

解决方案可能是使用 LINQ,如下例所示:

int[] test = { 1, 2, 1, 3, 3, 4, 5 };
var res = (from t in test select t).Distinct<int>();
foreach (var i in res)
{
    Console.WriteLine(i);
}

这将打印预期:
1
2
3
4
5

关于.net - 如何在 .net 中获取数组的唯一值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/83260/

相关文章:

c# - 托管 .NET 等同于 WinBase 的 CreateFile 和 WriteFile (kernel32.dll)

c# - 在 C# 中,如何让一组任务完成后运行一个任务?

c++ - 围绕枢轴 C++ 对数组进行分区

php - 无法在智能手机中获取文件的 tmp_name ($_FILES)

algorithm - 简单的基数估计算法

.net - Html.Editor用于附加ViewData

c# - 在 C# 中修剪部分文本文件的代码

Javascript reduce push individual sums + final sum

c - 如何在C中创建一个随机二维数组,其值仅重复两次

Mysql 唯一约束 > 16 列