What is C# and operator?

In C#, && is known as the Logical AND operator. If both the inputs are non-zero, the condition becomes true.

Input A Input B Output
0 0 0
0 1 0
1 0 0
1 1 1

In other words, the output would only be True when both A and B are True and False for all other cases.

Code

class LogocalAndOperator
{
static void Main()
{
bool a = false;
bool b = false;
System.Console.WriteLine("a = false and b = false");
if(a&&b)
{
System.Console.WriteLine("True");
}
else
{
System.Console.WriteLine("False");
}
// Now we will assign b to be True
// if we hadn't changed b to True and had rather
//changed a to true result would be saME
b = true;
System.Console.WriteLine("a = false and b = true or a = true and b = false");
if(a&&b)
{
System.Console.WriteLine("True");
}
else
{
System.Console.WriteLine("False");
}
//Now we can assign a to be true
a = true;
System.Console.WriteLine("a = true and b = true");
if(a&&b)
{
System.Console.WriteLine("True");
}
else
{
System.Console.WriteLine("False");
}
}
}

Free Resources