+ 1
I don't understand booleans...can anyone explain me this plzz
plz explain briefly i dont get what are booleans i just know they are true&false
4 Respuestas
+ 2
Darpan Kushwaha consider a case that you are trying to access some file content... if you get that file content, you are suppose to do further task otherwise not..
in this scenario, you can declare bool as true to indicate that all cases will be passed... in between while trying to access content, if anything goes wrong, you set it as false...at end, you simply write that do next steps only if bool has value as true...
feel free to ask for doubt...
+ 1
plz can u get me some examples
+ 1
Bool is a handy variable type when you know, there are only 2 options.
For example
Person.HasDriverLicence
A Person object, can have a property "HasDriverLicense".
This is either true or false.
For a method
bool ReadFromDataBase
if ReadFromDataBase was succesfull the method can return true.
If an error occurred ReadFromDataBase can return false.
Now ReadFromDataBase can be used in a if-statement
if (ReadFormDatabase)
{
//do something with the read data
}
else
{
//show error occurred
}
0
1 == True
0 == False
booleans == True / False