jae-l
5/11/2017 - 12:01 AM

Example of using logical operators for a truth table.

Example of using logical operators for a truth table.

bool x = true;
bool y = true;
Console.WriteLine("-------------------------------");
Console.WriteLine("Values: x = " + x + " | y = " + y);
Console.WriteLine("-------------------------------");
Console.WriteLine("!x = " + !x);  //  False
Console.WriteLine("x && y = " + (x && y));  //  True
Console.WriteLine("x || y = " + (x || y));  //  True
Console.WriteLine("x ^ y = " + (x ^ y));  //  False
Console.WriteLine();

x = true;
y = false;
Console.WriteLine("-------------------------------");
Console.WriteLine("Values: x = " + x + " | y = " + y);
Console.WriteLine("-------------------------------");
Console.WriteLine("!x = " + !x);  //  False
Console.WriteLine("x && y = " + (x && y));  //  False
Console.WriteLine("x || y = " + (x || y));  //  True
Console.WriteLine("x ^ y = " + (x ^ y));  //  True
Console.WriteLine();

x = false;
y = true;
Console.WriteLine("-------------------------------");
Console.WriteLine("Values: x = " + x + " | y = " + y);
Console.WriteLine("-------------------------------");
Console.WriteLine("!x = " + !x);  //  True
Console.WriteLine("x && y = " + (x && y));  //  False
Console.WriteLine("x || y = " + (x || y));  //  True
Console.WriteLine("x ^ y = " + (x ^ y));  //  True
Console.WriteLine();

x = false;
y = false;
Console.WriteLine("-------------------------------");
Console.WriteLine("Values: x = " + x + " | y = " + y);
Console.WriteLine("-------------------------------");
Console.WriteLine("!x = " + !x);  //  True
Console.WriteLine("x && y = " + (x && y));  //  False
Console.WriteLine("x || y = " + (x || y));  //  False
Console.WriteLine("x ^ y = " + (x ^ y));  //  False