Statements and Flow of Execution

The following sections detail the different statements that are available within the C# language.

Selection Statements

The selection statements are used to perform operations based on the value of an expression.


The if statement in C# requires that the condition inside the if statement evaluate to an expression of type bool. In other words, the following is illegal:1

// errorusing System;class Test{    public static void Main()    {       int value = 0;       if (value)       // invalid       {            System.Console.WriteLine("true");       }       if (value == 0)    // must use this        ...

Get A Programmer's Guide to C# 5.0, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.