Why is an if statement working but not a switch statement

You cannot have expressions in the case (prior to C# 7), but you can in the switch, so this will work:

switch (ConvertToMessageCode(msgComingFromFoo[1]))
{
    case Message.Code.FOO_TRIGGER_SIGNAL:
        break;
}

Where you will need to write ConvertToMessageCode to do the necessary conversion to the Message.Code enum. ConvertToMessageCode just abstracts the conversion details, you may find you do not need a separate method, but can make do with inline code in the switch statement, e.g., a cast.

Leave a Comment

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