【问题标题】:C# switch case Array contains string [closed]C# switch case 数组包含字符串 [关闭]
【发布时间】:2019-03-31 23:07:45
【问题描述】:

是否可以通过switch case查找字符串是否包含在数组中?

 string text = "blalbac";
 string arr[] = {"a","b","c"};

  switch (text)
  {
    case arr.Contains(filename):
      //do..
      break;
  }

【问题讨论】:

标签: c# arrays string switch-statement contains


【解决方案1】:

我不确定你想做什么。你想要类似的东西

foreach(string item in arr)
{
    if(text.Contains(item))
    {
        ...
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-20
    • 2014-10-18
    • 1970-01-01
    • 2012-08-18
    • 2018-07-04
    相关资源
    最近更新 更多