C# how to use enum with switch

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

    All the other answers are correct, but you also need to call your method correctly:

    Calculate(5, 5, Operator.PLUS))
    

    And since you use int for left and right, the result will be int as well (3/2 will result in 1). you could cast to double before calculating the result or modify your parameters to accept double

提交回复
热议问题