匹配具有多个值

时间:2017-03-13 08:46:08

标签: c#

我已经编写了一个程序,可以显示两个文本文件数组之间的相等性,我的问题是我有多个相等的值,我只希望一个值与另一个值匹配。有人可以帮我吗?

左侧的第2行值应与右侧的第4行值匹配,但输出显示第13行也匹配:

line 2 value on the Left should be match with line 4 value on the right but the output show that line 13 also match

这是我的代码

for (int i = 0; i <line.Length; i++)
 {
     for (int j = 0; j <lines.Length; j++)
     {
         if (line[i] == lines[j])
         {
             found = true;
             listBox3.Items.Add("PASS");
             break;
         }

     }

     if (found == false)
     {

         listBox3.Items.Add("FAIL: line " + (i + 1));
     }
     found = false;
 }

1 个答案:

答案 0 :(得分:1)

您可以使用Linq:

var areEquals = array1.All(x => array2.Count(y => y == x) == 1);
相关问题