What are Booleans types in C#?


For the Boolean type, the bool keyword is used and is an alias of System.Boolean.

It is used to declare variables to store the Boolean values, true and false.

Let us see an example to learn how to use bool in C#.

Example

using System;
public class Demo {
   static void Main() {
      bool val = true;
      int d = DateTime.Now.DayOfYear;
      val = (d % 2 == 0);
      if (val) {
         Console.WriteLine("days: even number");
      } else {
         Console.WriteLine("days:odd number");
      }
   }
}

Updated on: 23-Jun-2020

96 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements