+ 3
Bool in C#
Hey (: Can you please tell me when would you use bool in c# ? Why ? It could really help if you'd give an example (: Thanks in advance!
3 Answers
+ 5
inbal maslow beiber karsenty , there are some issues in your posted code. This can confuse people, even if you have given a hint for this. Thanks
- <int> and <if> are spelled upper case, but should be lower case
- <bool> in Console.WriteLine(bool) creates an error -> Invalid expression term 'bool'
Here is a sample that demonstrates how it could work. code is made for demonstration only, not for use in a real project.
Console.Write("please enter 1 letter: ");
char inpChar = Convert.ToChar(Console.ReadLine());
bool charState = char.IsLower(inpChar); // this checks if input is lower case. if Yes, charState will <true>, otherwise <false>
Console.WriteLine(inpChar);
Console.Write("input character is lower: ");
Console.WriteLine(charState);
+ 2
Is it like:
Int x = 2;
Int y = 5;
If(x<y){
Console.WriteLine(bool);}
else{
Console.WriteLine(bool);}
I know it's not the syntax, but that's how I think it supposed to look like....
+ 2
Some situations are either true or false. Nothing else in those cases you use bool.
Like
Ischecked for a checkbox
IsValid