Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C#

How to I declare a Bool variable a value

hello, I have a very simple question. how do I declare a Bool variable and assign it a value? I tried something like this, but got several errors.

bool collectedCoin? = Yes;

now this may seem stupid but I honestly dont know what is wrong. do I need to put double quotes before and after the yes? I thought you used double quotes for strings.

3 Answers

Damien Bactawar
Damien Bactawar
8,549 Points

Which language are you using? In C# it would be -

bool collectedCoin = true;

Bool is short for boolean which implies binary logic, true/false, 0/1.

oh yeah im so stupid i completely switched the true to yes haha! thank you!

yeah thats what I thought I just switched around the true and false to yes and no for some reason. that is exactly what I need. thank you Damien!