Chapter 4 Quick Reference


Chapter 4 Quick Reference

To

Do this

Example

Determine whether two values are equivalent

Use the == or != operator.

answer == 42

Compare the value of two expressions

Use the <, <=, >, or >= operator.

age >= 21

Declare a Boolean variable

Use the bool keyword as the type of the variable.

bool inRange;

Create a Boolean expression that is true only if two other conditions are true

Use the && operator.

inRange = (lo <= number)        &&  (number <= hi);

Create a Boolean expression that is true if either of two other conditions is true

Use the || operator.

outOfRange = (number < lo)          ||  (hi < number);

Run a statement if a condition is true

Use an if statement.

if (inRange)    process();

Run more than one statement if a condition is true

Use a block.

if (seconds == 59)  {      seconds = 0;      minutes++;  }

Associate different statements with different values of a controlling expression

Use a switch statement.

switch (current)  {    case '<':             ...            break;     default :            ...            break;  } 




Microsoft Visual C# 2005 Step by Step
Microsoft® Visual C#® 2005 Step by Step (Step By Step (Microsoft))
ISBN: B002CKYPPM
EAN: N/A
Year: 2005
Pages: 183
Authors: John Sharp

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net