我有两个字符串数组。我想从第一个数组中选择一个元素并与第二个数组的每个元素进行比较。如果第一个数组的元素存在于第二个数组的元素中,我想写例如(“元素存在”)或类似的东西。
这应该可以用两个 for 循环来做?
编辑
好的,我终于实现了我想要的使用此代码:
string[] ArrayA = { "dog", "cat", "test", "ultra", "czkaka", "laka","kate" };
string[] ArrayB = { "what", "car", "test", "laka","laska","kate" };
bool foundSwith = false;
for (int i = 0; i < ArrayA.Length; i++)
{
for (int j = 0; j < ArrayB.Length; j++)
{
if (ArrayA[i].Equals(ArrayB[j]))
{
foundSwith = true;
Console.WriteLine("arrayA element: " + ArrayA[i] + " was FOUND in arrayB");
}
}
if (foundSwith == false)
{
Console.WriteLine("arrayA element: " + ArrayA[i] + " was NOT found in arrayB");
}
foundSwith = false;
}
我希望这将有助于其他想要比较两个数组的人;)。这一切都与这个foundSwitch有关。Thx 再次寻求帮助。