Skip to main content

Posts

Showing posts with the label code best practice

Fixing Multiple Switch Case Problem in C#

 I n this Chapter we will see how we can fix growing switch case which cause code maintainability issue In our development projects we may have below situation where switch cases increase with time and getting difficult to maintain Let’s understand problem using System; class Program { static void ProcessOrder ( string orderType ) { switch (orderType) { case "NEW_ORDER" : Console.WriteLine( "Processing new order." ); // New order logic here break ; case "CANCEL_ORDER" : Console.WriteLine( "Cancelling order." ); // Cancel order logic here break ; case "SHIPPING" : Console.WriteLine( "Shipping order." ); // Shipping logic here break ; case "DELIVERED" : Console.WriteLine( "Ord...