これは単なる「ベストプラクティス」の質問です...
入力文字列を受け取り、コンテンツに基づいて変更する必要がある関数がありますが、特定の条件が満たされると、それ以降のすべての処理が停止します。
現時点では、「while(true)」ループを使用し、必要なものが得られたら「ブレーク」します。以下は疑似コードです。
string Input = "xyz";
string Output = string.Empty;
while (true)
{
if (Input.StartsWith("x"))
{
Output = "string starts with an X";
break;
}
if (Input.Contains("y"))
{
Output = "string has a 'y' in it";
break;
}
if (Input.IndexOf("z") == 2)
{
Output = "string has a 'z' as the 3rd character";
break;
}
Output = "string does not match any conditions";
break;
}
上記を達成するためのより「純粋な」方法はありますか?
ありがとう