我必须比较两个字符串数组,并将不同的索引作为整数?谁能帮我吗?
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)