CSharp/C# Tutorial - C# Boolean Type/Operators






C#'s bool type aliasing the System.Boolean type is a logical value that can be assigned the literal true or false.

We use the bool type to represent a ture or false value, for example, isRaining, isValid, isChecked.

Bool Conversions

No conversions can be made from the bool type to numeric types or vice versa.

Equality and Comparison Operators

== and != test for equality and inequality of any type, but always return a bool value.

The following code shows how to use the Equality and Comparison Operators.


int x = 1; 
int y = 2; 
int z = 1; 
Console.WriteLine (x == y); // False 
Console.WriteLine (x == z); // True 

For reference types, equality, by default, is based on reference, as opposed to the actual value of the underlying object.