If-Statement

In this we will discuss about C# If-Statement.



If-Statements are used for making decision,they are very useful and likely to be used frequently. The condition must be Boolean,so it is either true or false. Use if to specify a block of code to executed.


Syntax:-

if(condition)
{
.....code to be executed
}
*******



using System;

class Program
{
       static void Main()
       {
           string username = null;

           Console.WriteLine("Enter username: ");
           username = Console.ReadLine();

if  (username == "technicalkiduniya")

                   {
                       Console.WriteLine("Welcome to +  username);
                    }
                    Console.ReadLine();
              }
}


Here,first we have made a variable called username which is null,and then we request the user's input.If the users enter "technicalkiduniya" then "Welcome to technicalkiduniya" will display;otherwise nothing will happen as the condition is false.






Comments

Popular posts from this blog

ASP.NET Overview

SQL AND ,OR, NOT Operators

SQL Joins