What are Booleans types in C#?

CsharpProgrammingServer Side Programming

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");
      }
   }
}
raja
Published on 18-Sep-2018 12:40:22
Advertisements