eBabel Blog

Make a website

70-536 exam: switch statement

19 March 2010

The switch statement is part of the C# Language Specification, and so is somehow a deeper part of C# than the core and system library dll files (mscorlib.dll & system.dll)

Here's a very simple switch condition based on user-input:

using System;

class SwitchTest
{
	static void Main()
	{
		n = Console.ReadLine();
		switch (n)
		{
			case "1":
			case "2":
			case "3":
				Console.WriteLine("1, 2 or 3.");
				break;
			default:
				Console.WriteLine("Other");
				break;
		}
	}
}

NB This a very basic switch statement, the input of 3 has the expected result "1, 2 or 3." but "3 " with a white space after the number 3 returns "Other".

If you liked this blog post, you may want to subscribe to my news feed in your RSS reader.