Friday 17 August 2018

C#: Ternary operator( ?: )

Returns one of two expressions depending on a condition.

Syntax
test ? expression1 : expression2

Returns expression1 if the “test” condition evaluates to true other wise returns expression2.

Program.cs

using System;

class Program
{
    static void Main(string[] args)
    {
        int a = 100;

        bool flag = a > 10 ? true : false;
        Console.WriteLine("flag = {0}", flag);
    }
}


Output
flag = True




Previous                                                 Next                                                 Home

No comments:

Post a Comment