How can I compare multiple variables to a single condition?

后端 未结 7 779
时光取名叫无心
时光取名叫无心 2020-12-19 16:06

I have this:

if (input.Text.ToUpper() == \"STOP\")

But there are so many possible values that I wouldn\'t be able to specify them all sepa

7条回答
  •  我在风中等你
    2020-12-19 16:40

    You could use a collection like array and Enumerable.Contains:

    var words = new[]{ "STOP", "END", "NO", "YES" };
    if(words.Contains(input.Text.ToUpper()))
    {
         // ...      
    }
    

提交回复
热议问题