Use bool type variable - CSharp Language Basics

CSharp examples for Language Basics:boolean

Description

Use bool type variable

Demo Code

using System;//from   w w  w. j  a v  a 2  s.  c  o  m
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
   static void Main(string[] args)
   {
      // Two logical (Boolean) variables
      bool thePrettiestGirlLovesMe = true;
      bool iAmHungry = false;
      // Use exclamation mark to negate logical value
      bool iAmNotHungry = !iAmHungry;
      // Output
      Console.WriteLine("She loves me: " + thePrettiestGirlLovesMe);
      Console.WriteLine("I am hungry: " + iAmHungry);
      Console.WriteLine("I am not hungry: " + iAmNotHungry);
   }
}

Result


Related Tutorials