使用带开关string.Contains()() [英] Use string.Contains() with switch()
本文介绍了使用带开关string.Contains()()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我做的,我使用C#应用程序
IF((message.Contains(测试)))
{
Console.WriteLine(是);
}否则如果((message.Contains(测试2))){
Console.WriteLine(是为测试2);
}
有是没有办法更改为开关( )
的如果()
语句?
解决方案
< 。p>您可以在第一次做检查,然后使用开关,只要你喜欢 例如:
字符串str =参数; // test1..test2..test3 ....
如果回报(message.Contains(STR)!);
然后
开关(STR)
{
案测试1:{}打破;
案测试2:{}打破;
默认:{}打破;
}
I'm doing an C# app where I use
if ((message.Contains("test")))
{
Console.WriteLine("yes");
} else if ((message.Contains("test2"))) {
Console.WriteLine("yes for test2");
}
There would be any way to change to switch()
the if()
statements?
解决方案
You can do the check at first and then use the switch as you like.
For example:
string str = "parameter"; // test1..test2..test3....
if (!message.Contains(str)) return ;
Then
switch(str)
{
case "test1" : {} break;
case "test2" : {} break;
default : {} break;
}
这篇关于使用带开关string.Contains()()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文