how do booleans work? c# | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

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!

21st Mar 2019, 3:10 AM
Julia García
Julia García - avatar
5 Answers
+ 8
• 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
21st Mar 2019, 11:15 AM
Danijel Ivanović
Danijel Ivanović - avatar
21st Mar 2019, 9:35 AM
VEDANG - avatar
+ 1
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.
21st Mar 2019, 9:40 PM
Pavel Šesták
Pavel Šesták - avatar
+ 1
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
23rd Mar 2019, 1:06 AM
George S Mulbah II
George S Mulbah II - avatar
Its a comparision like math
3rd Apr 2019, 5:05 AM
Tony Stark
Tony Stark - avatar