Open ahmethudaiaydin opened 6 years ago
which where?
Every switch. Specially, for the math operators ie: '+', '-' ....
I can use if else but the code will be long. so,I will use switch case for choose way to calculate.
No, I'm not talking about using if else. You can create classes for every math operator then use these classes in your code without an if or switch-case. Like:
abstract class MathOperator{ abstract string sign{get;set} // "+", "-", "/" or "*" abstract int process(int firstValue, int secondValue); } class PlusOperation :MathOperator { string sign { get {return "+";}} int process(int first, int second){ return first + second; } }
class MinusOperation: MathOperator{ ..... }
You can collect a new instance of these operations and when you want to calculate, you call call process method in a foreach.
Try not to use "switch-case". Do you think it is possible?