.NET Coding Best Practices -part 3
Published in
Jun 6, 2022
Another common code we see a bunch of if statements as shown below
Above should be avoided, better to follow Open Closed Principle and have common interface and different child class having specific implementation, with this approach any change in program won’t impact other parts of the program.
Also, above code should be written using switch statement as below
Or even better approach to use latest C# 7 feature to use switch expression like below, it is more readable and more possibilities for computation in switch expression