Introduction
Decision logic is based on expressions, known as Boolean expressions that evaluate to "true" or "false". Developers use various types of operators to create Boolean expressions that meet their coding requirements. When the expressions are evaluated, the code execution branches based on the result. The C# language supports a wide range of operators (such as equality, comparison, and Boolean operators), each of which serves a specific purpose when implementing decision logic.
Suppose you've been selected to work on a series of C# console applications that are used to process customer data and user supplied inputs. Each application requires you to implement decision logic that achieves data processing requirements and associated business rules. The data processing requirements and business rules vary for each application. For example, applications that process customer orders might need to evaluate the status of the customer before taking any action. To prepare for this upcoming assignment, you'll complete some practice activities that implement Boolean expressions and C# operators.
In this module, you learn about Boolean expressions, and you use different types of operators to evaluate expressions for equality, inequality, and comparison. You also learn to use a special inline version of an if
statement (a conditional operator) that produces an "either / or" result.
By the end of this module, you are able to write code using any combination of C# operators to implement decision logic in your applications.
Learning objectives
In this module, you will:
- Use operators to create Boolean expressions that test for comparison and equality.
- Use built-in methods of the string class to perform better evaluations on strings.
- Use the negation operator to test for the opposite of a given condition.
- Use the conditional operator to perform an inline evaluation.
Prerequisites
- Experience with basic coding tasks such as instantiating variables, using various data types, and sending output to a console window.
- Experience using the
if-elseif-else
construct. - Experience using the
Random
class to generate a random number. - Experience using Visual Studio Code to create and run simple console applications.