C# if statement | c# if | if c# - c# - c# tutorial - c# net



C# If Statement

C# If Statement

What is if statement in C# ?

  • In C#, an if statement consists of a Boolean expression followed by one or more statements.
 c sharp if statement string

Syntax:

if (condition) 
{
   condition statement is true;
}

if statement in c#

if statement in c#

C# Sample Code - C# Examples:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace wikitechy_if_condition
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = 5;

	        if (n <= 5)

	        {
              Console.WriteLine("wikitechy says this condition is true");
            }

           Console.ReadLine();

        }
    }
}

Code Explanation:

 c sharp if operator
  1. Here n = 5 is an integer variable value as 5.
  2. Here, if (n <= 5) expression specifies the n =5 is less than, or equal to 5 i.e., (5 <= 5), which executes the statement "wikitechy says this condition is true".

Sample C# examples - Output :

 nested if else in c sharp
  1. Here the statement executes the if condition by printing the statement "Wikitechy says this condition is true".

Related Searches to C# if statement | c# if | if c#