Here i am Posting the simple program as well as most basic program which will show you
"How to use AND Operator(&&)".
It will be most helpful for the beginners who start learning C#.
In this example i have hard coded the value of username and password which i mention in the code comment(//).
ENJOY CODING!!!!!
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication10 { class Program { static void Main(string[] args) { string name, password; Console.Write("Enter Username = ");//username get from user. name=Console.ReadLine(); Console.Write("Enter Password = ");//password get from the user. password = Console.ReadLine(); //here it will check whether the value is true or not. if (name == "admin" && password == "admin123")//in this statement i have hard coded. { Console.WriteLine("Login Successful");//if the statement will true than it will print this. } else { //if the statement will be false than it will print below statement. Console.WriteLine("Invalid Username OR Password Please Try Again!!!"); } Console.ReadLine(); } } }
Output :
When the value will be TRUE than it will give this output.
When the value will be FALSE than it will give this output.
Tags:
csharp.net