how do booleans work? c# | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
+ 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
5 ответов
+ 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ć
21st Mar 2019, 9:35 AM
VEDANG
+ 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
+ 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
0
Its a comparision like math
3rd Apr 2019, 5:05 AM
Tony Stark
Актуальное сегодня
Help!