Using .StartsWith in a Switch statement?

Since C# 7 you can do the following:

switch(subArea)
{
    case "4100":
    case "4101":
    case "4102":
    case "4200":
       return "ABC";
    case "600A":
       return "XWZ";
    case string s when s.StartsWith("3*"):
       return "123";
    case string s when s.StartsWith("03*"):
       return "123";
    default:
       return "ABCXYZ123";
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)