C# how to use enum with switch

前端 未结 11 463
小鲜肉
小鲜肉 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:24

    Your code is fine. In case you're not sure how to use Calculate function, try

    Calculate(5,5,(Operator)0); //this will add 5,5
    Calculate(5,5,Operator.PLUS);// alternate
    

    Default enum values start from 0 and increase by one for following elements, until you assign different values. Also you can do :

    public enum Operator{PLUS=21,MINUS=345,MULTIPLY=98,DIVIDE=100};
    

提交回复
热议问题