Key Concepts

Review core concepts you need to learn to master this subject

Boolean Expressions

// These expressions all evaluate to a boolean value. // Therefore their values can be stored in boolean variables. bool a = (2 > 1); bool b = a && true; bool c = !false || (7 < 8);

A boolean expression is any expression that evaluates to, or returns, a boolean value.

Understanding Logic in C#
Lesson 1 of 2
  1. 1
    Computers are constantly checking the state of something. Is this program running or not? Does this variable exist or not? Is this value equal to that value? These yes or no questions demonstrate…
  2. 2
    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 t…
  3. 3
    When writing a program, we often need to check if a value is correct or compare two values. Comparison operators allow us to compare values and evaluate their relationship. Rather than evaluating t…
  4. 4
    We can also use operators that use Boolean values as inputs and output. Logical operators, also known as Boolean operators, can be used to create Boolean expressions. Logical operators include: -…
  5. 5
    As we saw in the truth table, a Boolean expression that uses logical operators can be as simple as evaluating two boolean values: bool answer = true && false; // evaluates to False In this case, …
  6. 6
    Great job! You just learned about logic and boolean values, including: - How to define variables with a bool data type - How to use comparison operators with different data types to return boolean …

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo