gpt4 book ai didi

c# - 如何比较两个字符串数组的序列

转载 作者:太空宇宙 更新时间:2023-11-03 18:37:56 25 4
gpt4 key购买 nike

我有两个字符串数组

string[] a; 
string[] b;

如何发现数组a中的元素顺序与数组b相似?

因为我使用的是 .net2.0,所以我无法使用 LINQ。

编辑

这是我试过的

foreach (string val2 in a)
{
foreach (string val1 in b)
{
if (val1 == val2)
{
// Values are same - continue processing
}
else
{
// Value not same -- exit }
}
}

最佳答案

    private bool Compare(string[] a, string[] b)
{
if (a.Length != b.Length) return false;

for (int i = 0; i< a.Length; i++)
if (a[i] != b[i]) return false;

return true;
}

关于c# - 如何比较两个字符串数组的序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12703945/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com