Core C#

Logical Operators

This C# program demonstrates how the logical operators are used.

Program.cs

using System;

namespace XoaX {
    class Program {
        static void Main(string[] args) {
            bool bP = true;
            bool bQ = false;
            Console.WriteLine("OR");
            Console.WriteLine("({0} || {1}) = " + (bP || bQ), bP, bQ);
            Console.WriteLine("({0} || {0}) = " + (bP || bP), bP, bQ);
            Console.WriteLine("({1} || {0}) = " + (bQ || bP), bP, bQ);
            Console.WriteLine("({1} || {1}) = " + (bQ || bQ), bP, bQ);
            Console.WriteLine("AND");
            Console.WriteLine("({0} && {1}) = " + (bP && bQ), bP, bQ);
            Console.WriteLine("({0} && {0}) = " + (bP && bP), bP, bQ);
            Console.WriteLine("({1} && {0}) = " + (bQ && bP), bP, bQ);
            Console.WriteLine("({1} && {1}) = " + (bQ && bQ), bP, bQ);
            Console.WriteLine("NOT");
            Console.WriteLine("!{0} = " + !bP, bP, bQ);
            Console.WriteLine("!{1} = " + !bQ, bP, bQ);
        }
    }
}
 

Output

OR
(True || False) = True
(True || True) = True
(False || True) = True
(False || False) = False
AND
(True && False) = False
(True && True) = True
(False && True) = False
(False && False) = False
NOT
!True = False
!False = True
Press any key to continue . . .
 
 

© 2007–2024 XoaX.net LLC. All rights reserved.