Click here to Skip to main content
15,886,258 members

Comments by Dan Colasanti (Top 1 by date)

Dan Colasanti 21-Jul-14 17:41pm View    
Reason for my vote of 1 \n I don't agree that this is a good alternative to using a switch statement in these simple cases. The correct alternative is to use an if-else statement. Using a Dictionary of Funcs is too cumbersome and memory intensive. Just because you can do what you have shown and it looks less messy than a switch statement, doesn't make it good programming. The solution is this:


if (x < 3) Console.WriteLine("Smaller than 3");
else if (x < 30) Console.WriteLine("Smaller than 30");
else if (x < 300) Console.WriteLine("Smaller than 300);
else Console.WriteLine("Larger than 299");