この C# コードは単純です。
このコードのシナリオ:
単語が一致すると、予期しない出力が発生します。
単語が見つかりました 単語が見つかりません 見つかったの値は次のとおりです: True
単語が一致しない場合、期待される出力が得られます。
単語が見つかりません found の値: False
static void Main()
{
string[] words = { "casino", "other word" };
Boolean found = false;
foreach (string word in words)
{
if (word == "casino")
{
found = true;
goto Found;
}
}
if(!found)
{
goto NotFound;
}
Found: { Console.WriteLine("The word is found"); }
NotFound: { Console.WriteLine("The word is not found"); }
Console.WriteLine("The value of found is: {0}", found);
Console.Read();
}