在switch语句中使用对象的string.contains方法? [英] Use an object's string.contains method within a switch statement?

查看:78
本文介绍了在switch语句中使用对象的string.contains方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上与以下内容类似:

Basically something along the lines of:

switch (string.contains(x))
{
    case(x = "asdf"):
        break;
    case(x = "jkl"):
        break;
    case(x = "qwerty"):
        break;
}

对不起,我理想的情况是让switch语句检查字符串中的几个不同值,并根据它在字符串中找到的值来执行相应的代码.

edit: Sorry guys, what I'd ideally like is to have the switch statement check the string for several different values, and depending on which of the values it finds inside the string, execute the appropriate code.

推荐答案

不幸的是,您不能这样做,但是可以应用功能模式匹配".在此处阅读有关操作方法的信息:

You can't do this unfortunately, however you can apply "functional pattern matching". Read up here on how to do it:

http://codebetter.com/matthewpodwysocki/2008/09/16/functional-c-pattern-matching/

这篇关于在switch语句中使用对象的string.contains方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆