logo search
Учебник_ПОА

Remarks

The simplest form of conditional branching uses the if construct. You can use an else clause with the if construct, and if constructs can be nested.

using System;

class Program

{

static void Main()

{

int x = 1;

int y = 1;

if (x == 1)

Console.WriteLine("x == 1");

else

Console.WriteLine("x != 1");

if (x == 1)

{

if (y == 2)

{

Console.WriteLine("x == 1 and y == 2");

}

else

{

Console.WriteLine("x == 1 and y != 2");

}

}

}

}

Note:

Unlike C and C++, if statements require Boolean values. For example, it is not permissible to have a statement that doesn't get evaluated to a simple True or False, such as (a=10). In C#, 0 cannot be substituted for False and 1, or any other value, for True.