📜  switch case c# contains - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:21.392000             🧑  作者: Mango

代码示例1
Correct final syntax for [Mr. C]s answer.

With the release of VS2017RC and its C#7 support it works this way:

switch(message)
{
    case string a when a.Contains("test2"): return "no";
    case string b when b.Contains("test"): return "yes";
}
You should take care of the case ordering as the first match will be picked. That's why "test2" is placed prior to test.