Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C# Sharp Exercises: Reverse a boolean value

C# Sharp Basic: Exercise-87 with Solution

Write a C# Sharp program to reverse a boolean value.

Sample Solution:

C# Sharp Code:

using System;
namespace exercises
{
    class Program
    {
        static void Main(string[] args)
        {
           bool cat = false;
           bool dog = true;
           Console.WriteLine("Original value: "+cat);
           Console.WriteLine("Reverse value: "+test(cat));
           Console.WriteLine("Original value: "+dog);
           Console.WriteLine("Reverse value: " + test(dog));
        }
        public static bool test(bool boolean)
        {
            return !boolean;
        }
    }
}

Sample Output:

Original value: False
Reverse value: True
Original value: True
Reverse value: False

Flowchart:

Flowchart: C# Sharp Exercises - Reverse a boolean value.

C# Sharp Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Write a C# Sharp program to get the number of letters and digits in a given string.
Next: Write a C# Sharp program to find the sum of the interior angles (in degrees) of a given Polygon. Input number of straight line(s).

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.