Learn

In C#, we can represent Boolean values using the bool data type. Booleans, unlike numbers or strings, only have two values: true and false.

To define a variable as a boolean, you define the data type as bool. Then write the variable name and set it equal to the value, either true or false:

bool variableName = true;

The variable is named variableName, its of type bool, and its value is true.

While we use the words true and false to represent boolean values, it’s important to remember that they are different from the strings "true" and "false".

Instructions

1.

Time to practice writing variables that use a bool data type!

Answer these True/False questions by saving your answer to the specified variables.

True or False: The number 500 is greater than 24.

Save your answer to a variable named answerOne.

2.

True or False: “coffee” contains the letter “a”.

Save your answer to a variable named answerTwo.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?