Conditional Operator - CSharp Language Basics

CSharp examples for Language Basics:Operator

Introduction

The conditional operator has the following format:

Condition ? if_true_statement : if_false_statement;

Demo Code

class MainClass//  ww  w . j  a v  a2s .  c om
{
   static void Main()
   {
      int Val1 = 1;
      int Val2 = 0;
      int result;
      result = (Val1 == Val2) ? 1 : 0;
      System.Console.WriteLine("The result is {0}", result);
   }
}

Result


Related Tutorials