The if statement - CSharp Language Basics

CSharp examples for Language Basics:if

Introduction

An if statement executes a statement if a bool expression is true. For example:

Demo Code

using System;//w ww.ja  v a 2  s  .c o  m
class Test
{
   static void Main(){
      if (5 < 2 * 3)
         Console.WriteLine ("true");       // true
      }
}

Result

The statement can be a code block:

Demo Code

using System;//w  w  w  .j a v  a2  s . co m
class Test
{
static void Main(){

     if (5 < 2 * 3)
     {
       Console.WriteLine ("true");
       Console.WriteLine ("Let's move on!");
     }

}
}

Result


Related Tutorials