C#如何获取数组中不同索引的数量?

问题描述 投票:0回答:1

我必须比较两个字符串数组,并将不同的索引作为整数?谁能帮我吗?

c# visual-studio-2019
1个回答
0
投票
  public static List<int> GetDiffIndex(string[] one, string[] two){
    List<int> diff = new List<int>();
    for(var i = 0; i < Math.Min(one.Length, two.Length); i++)
      if(one[i]!=two[i])
        diff.Add(i);
    return diff;
  }

要使用:

Console.WriteLine(String.Join(",",GetDiffIndex(new[]{"hey","oi","oof"},new[]{"hey","nani"})));

如果您只想要差异量

Console.WriteLine(GetDiffIndex(new[]{"hey","oi","oof"},new[]{"hey","nani"}).Count)
© www.soinside.com 2019 - 2024. All rights reserved.