gpt4 book ai didi

c# - 如何比较 foreach 内的 foreach 值

转载 作者:行者123 更新时间:2023-11-30 21:09:19 24 4
gpt4 key购买 nike

如何比较这个嵌套的 foreach 中的值。 我想比较,如果它们匹配打印 YES 例如。干杯

using System;

class Program
{
static void Main()
{
// Use a string array to loop over.
string[] ferns =
{
"apple",
"Equisetopsida",
"Marattiopsida",
"Polypodiopsida"
};

string[] fruits=
{
"apple",
"mango",
"Marattiopsida",
"Polypodiopsida"
};
// Loop with the foreach keyword.
foreach (string value in ferns)
{
Console.WriteLine(value);

foreach (string value in fruits)
{
Console.WriteLine(value);
}

//I would like to compare values here.
//Compare frens values against fruits values.
//How can i achieve this


}
}
}

最佳答案

foreach (string fern in ferns)
{
Console.WriteLine(fern);

foreach (string fruit in fruits)
{
Console.WriteLine(fruit);

if(fruit.Equals(fern))
Console.WriteLine("YES");
}
}

关于c# - 如何比较 foreach 内的 foreach 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9076154/

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