如果使用" II"检查同一个查询的多种可能性 [英] Using If "II" to check for multiple possibilities of the same query
本文介绍了如果使用" II"检查同一个查询的多种可能性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这通常是我能在网上找到很容易地,但我认为我有麻烦的措辞,所以我道歉,如果这是一个重复的问题。
我我想找一个更简洁的方式做一个IF /或检查相同的查询。例如:
如果(SCHECK ==字符串1|| SCHECK ==字符串2|| SCHECK ==STRING3 )
{
MessageBox.Show(SCHECK +是三个可能的字符串之一);
}
我在寻找一个更清洁更简洁的方式做同样的如果/要么。我希望像这些的工作,但他们当然不:
如果(SCHECK ==字符串1|| 字符串2||STRING3){}
如果(SCHECK ==(字符串1||字符串2||STRING3)){}
解决方案
创建一个包含各种可能性的集合:
如果(新[] {字符串1,字符串2,STRING3}。载有(谢克)){}
This is normally something I can find online pretty easily but I think I'm having trouble wording it so I apologize if this is a duplicate question.
I'm looking for a more concise way to do an IF/OR check for the same query. For example:
if (sCheck == "string1" || sCheck == "string2" || sCheck == "string3")
{
MessageBox.Show(sCheck + " is one of the three possible strings.");
}
I'm looking for a cleaner more concise way to do the same If/Or. I was hoping something like these would work but of course they don't:
if (sCheck == "string1" || "string2" || "string3") { }
if (sCheck == ("string1" || "string2" || "string3")) { }
解决方案
Create a collection that holds the different possibilities:
if(new[] {"string1", "string2", "string3" }.Contains(sCheck)) { }
这篇关于如果使用" II"检查同一个查询的多种可能性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文