CHAPTER 11

image

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.

If

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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.