C# – Parsing commands and arguments in a console app

In a console app there are two ways to get commands: Command line arguments passed into your program via Main(string[] args). User input from Console.ReadLine() (which you then split into a string[]). After getting a command, you have to parse it to figure out what code to execute. Typically commands have the following format: commandName … Read more

C# – Working with tuples

Here’s how you create a tuple: Tuples are containers for two or more variables. Without tuples, you’d have to use a class/struct, like this: In other words, tuples provide a convenient alternative to class/structs. Instead of having tons of data container classes, you can use tuples. In this article, I’ll show examples of how to … Read more

Refactoring the Switch Statement code smell

The Switch Statement code smell refers to using switch statements with a type code to get different behavior or data instead of using subclasses and polymorphism. In general, it looks like this: This switch(typeCode) structure is typically spread throughout many methods. This makes the code difficult to extend, and violates the Open-Closed Principle. This principle … Read more