If Else Statement With AND OR Operator in C# Language

Introduction

If Else statements to tell your program to do certain things only when the conditions you set up are true or not true. If else statements check if two things are equal. That is when you use the == operator. That different from the equal sine(=) operator. which you can use to set a value. We have check multiple condition in if else through using "AND" ( && ) or "OR"( || ) operator. See in given below figure.

If else figure with AND operator:

  i1.jpg

If else figure with OR operator:

 i2.jpg

Example

using System; 

using System.Collections.Generic; 

using System.Linq; 

using System.Text; 

 

namespace if_else_statement_in_c_sarp

{

    class Program

    {

        static void Main(string[] args)

        {

            string id = "abc";

            int password = 123;

            int reset = 456;

           

            if (id == "abc" && password==123)   //Every if statement is Start with a conditional test

 

            //Always use Two equals(==) sine to check , if two things are equal to each other

            {

                Console.WriteLine("helo {0}",id); // Inside statement run , When If Statement is True               

            }

 

            else if(reset==456 || password==123)          //if else conditional statement with || ( 'OR' ) operator

            {

                Console.WriteLine("helo {0}", id); // Inside statement run , When only one Statement is True              

            }

            Console.ReadLine();

        }

    }

}


Output


i3.jpg

Ebook Download
View all
Learn
View all