CSharp - Write program to Working with Logical Boolean Values

Requirements

In programming, you often work with logical values, which are the values of "yes" and "no." or true false.

Hint

The type for logical values is called bool in C#.

The value "yes" is written as true, and the value "no" is written as false.

Demo

using System;

class Program/*from   ww  w .  java  2 s.c o m*/
{
    static void Main(string[] args)
    {
        // Two logical (Boolean) variables 
        bool goingToRain = true;
        bool iAmHungry = false;

        // Use exclamation mark to negate logical value 
        bool iAmNotHungry = !iAmHungry;

        // Output 
        Console.WriteLine("She loves me: " + goingToRain);
        Console.WriteLine("I am hungry: " + iAmHungry);
        Console.WriteLine("I am not hungry: " + iAmNotHungry);

    }
}

Result

You can use an exclamation mark to negate a logical value (to flip it from "yes" to "no" and back again).