更新时间:2023-11-02 23:44:46
例如:
字符串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;
}