how do booleans work? c# | SoloLearn: Learn to code for FREE!


how do booleans work? c#

i don’t really understand how they work and how i should use them, can u give me an example? thank you so much!

3/21/2019 3:10:43 AM

Julia García

5 Answers

New Answer


• Bool is often used in expressions. Many expressions evaluate to a boolean value. Represented in one byte, the bool type represents truth. For example: A bool can be assigned to the 'true' and 'false' literals. We set the bool variable to 'true'. And then we invert the value of the bool using the exclamation operator. bool val = true; if (val) { Console.WriteLine(val == true); } val = !val; if (!val) { Console.WriteLine(val == false); } Output: True True


You can visit


boolean is a logical operator. its can store a logical value. for example component is visible? true/false. is x>y? true/false. you can used it in conditions. its cheap for memory storage. because boolean need to reserve just 1 bit. logical 1 or logical 0. with this you can use logical operator and or xor. its very usefull thing.


Boolean is are logical operator for comparing stating a logic if a certain condition Try taking a look at few this mathematics topic Boolean Algebra


Its a comparision like math