Boolean type of value type:
The Boolean type is used to represent the two concepts of 'true' and 'false'. Although it looks very simple, it is actually used very widely. We know that computers It uses binary to represent various data, and there are only 0 or 1 inside it. The logical variables represented by the Boolean type are only 2, True or False.
Here we compare C/C++, Boolean type The meaning in C/C++ is the same as that in C#. It represents the two values of 'true' or 'false'. 0 represents 'false' and other non-0 numbers represent 'true'. This informal expression is used in C#. Abandoned. In C#, True and False cannot be replaced by other values, and there is no conversion between integer types and Boolean types. That is to say, it is illegal to convert integer types into Boolean types.
bool x=1 //Error
bool x=true or x = false //Correct
Next, define a Boolean variable and output:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Example { class Program { static void Main(string[] args) { bool b=true; Console.WriteLine(b); } } }
The result is:
True
The above is the content of C# Learning Diary 05---Boolean type of data type. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!