Search This Blog

Thursday, October 24, 2013

Bool Type C Sharp

C# > Types > Bool

bool type in C# it is used to declare variables to store the Boolean values, true and false.

Examples:

bool b = true;
MessageBox.Show(b.ToString()); // Display True

b = null; //Error: Cannot convert null to 'bool' because it is a non-nullable value type

If you need a Boolean variable that can also have a value of null, use bool?

bool? b = true;
b = null; //Ok