
C# 6 and .NET Core 1.0

Every application needs to be able to select from choices and branch along different code paths. The two selection statements in C# are if
and switch
, also known as if-else
and switch-case
. You can use if
for all your code but switch
can simplify your code in some common scenarios.
Start Microsoft Visual Studio 2015. In Visual Studio, press Ctrl + Shift + N or choose File | New | Project….
In the New Project dialog, in the Installed Templates list, select Visual C#. In the list at the center, select Console Application, type the name Ch03_SelectionStatements, change the location to C:\Code, type the solution name Chapter03, and then click on OK.
At the top of the Program.cs
file, statically import the System.Console
type, as follows:
using static System.Console;
The if-else
statement determines which branch to follow by evaluating a Boolean expression. The else
block is optional. if-else
statements can be nested and combined. Each Boolean expression can...
Change the font size
Change margin width
Change background colour