简体   繁体   English

查找二维字符串数组的唯一行输出

[英]Find Unique line output of a 2 dimensional string array

I have the following string; 我有以下字符串;

string[,] test=
{
  {"0","0"},
  {"0","0"},
  {"0","0"},
  {"0","1"},
  {"5","0"},
};

I'd like to find a way to search the array for all lines that are unique. 我想找到一种在数组中搜索所有唯一行的方法。 So my desired output array would be. 所以我想要的输出数组是。

string[,] output=
{
  {"0","0"},
  {"0","1"},
  {"5","0"},
};

Does anyone have any simple ideas on how to achieve this? 有谁对实现这一目标有任何简单的想法?

you can do this with linq just call Distinct to select only unique values, like this 您可以使用linq做到这一点,只需调用Distinct即可仅选择唯一值,例如

var query = (from arr in test
             from value in arr
             select value).Distinct();

or you can try the following method, This simply flattens the nested arrays into a sequence and calls Distinct to find the distinct elements. 或者您可以尝试以下方法,这只是将嵌套数组展平为一个序列,然后调用Distinct查找不同的元素。 source this answer 找出答案

var distinct = test.SelectMany(a => a).Distinct().ToArray();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM