基本上是这样的:
switch (string.contains(x))
{
case(x = "asdf"):
break;
case(x = "jkl"):
break;
case(x = "qwerty"):
break;
}
编辑:抱歉,伙计们,我最理想的做法是让 switch 语句检查字符串中的几个不同值,并根据它在字符串中找到的值执行适当的代码。
最佳答案
不幸的是,您不能这样做,但是您可以应用“功能模式匹配”。在此处阅读如何操作:
http://codebetter.com/matthewpodwysocki/2008/09/16/functional-c-pattern-matching/
关于c# - 在 switch 语句中使用对象的 string.contains 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6918176/