C# how to use enum with switch

前端 未结 11 477
小鲜肉
小鲜肉 2020-12-08 06:04

I can\'t figure out how to use switches in combination with an enum. Could you please tell me what I\'m doing wrong, and how to fix it? I have to use an enum to make a basic

11条回答
  •  庸人自扰
    2020-12-08 06:49

    You don't need to convert it

    switch(op)
    {
         case Operator.PLUS:
         {
            // your code 
            // for plus operator
            break;
         }
         case Operator.MULTIPLY:
         {
            // your code 
            // for MULTIPLY operator
            break;
         }
         default: break;
    }
    

    By the way, use brackets

提交回复
热议问题