Sponsored Ad

Sunday, March 13, 2011

How to use Conditional Operator in C# | Example

This program will help beginners to learn the conditional operator provided by C#. if condition is true it will give before : (colon) results otherwise give after :(colon) results.

How to use Conditional Operator in C# | Example

C# Code Example for Conditional Operator:

using System;

namespace MyApp
{
    class conditional_class
    {
        static void Main()
        {
            bool my_bool = true;
            string strResult = my_bool ? "True condition" : "False condition";
            Console.WriteLine("{0}", strResult);
            Console.WriteLine("Condition is {0}", my_bool ? "The condition is true" : "The condition is false");
            Console.Read();
        }
    }
}

No comments:

Post a Comment

Sponsored Ad

Development Updates