Latest web development tutorials

C # if statement

C # judge C # judge

If a Boolean expression followed by a statementby the one or more statements.

grammar

C #,if the syntax of the statement:

if (boolean_expression)
{
   / * If the Boolean expression is true will execute statement * /
}

If the Boolean expression istrue, the if statement within a block of code will be executed.If the Boolean expression isfalse, if the first set of codes after the statement (after the close parenthesis) will be executed.

flow chart

The if statement in C #

Examples

using System;

namespace DecisionMaking
{
    
    class Program
    {
        static void Main (string [] args)
        {
            / * Local variable definitions * /
            int a = 10;

            / * Use the if statement to check the conditions Boolean * /
            if (a <20)
            {
                / * If the condition is true, the output following statement * /
                Console.WriteLine ( "a less than 20");
            }
            Console.WriteLine ( "a value is {0}", a);
            Console.ReadLine ();
        }
    }
}

When the above code is compiled and executed, it produces the following results:

a less than 20
a value of 10

C # judge C # judge