我被数组问题困扰并需要帮助。
我有两个数组,并使用foreach循环进行比较。如果在
(我必须使用循环来解决这个问题)
我有两个数组,并使用foreach循环进行比较。如果在
winningNumbers
中有两个数字与someNumbers
匹配,程序将写入“you won” 。如果只有一个匹配,输出应为“You lost”。(我必须使用循环来解决这个问题)
int[] someNumbers = { 1, 2, 3, 4, 5, 6 };
int[] winningNumbers = { 1, 2, 13, 14, 15, 16 };
bool winning = false;
foreach (var item1 in someNumbers)
{
foreach (var item2 in winningNumbers)
{
if (item1 == item2)
{
winning = true;
}
}
}
if (winning == true )
{
Console.WriteLine("You won");
}
else
{
Console.WriteLine("You lost");
}