Operators & Expressions
What Are Operators?
If variables are the nouns in your code, operators are the verbs. They do stuff — add numbers, compare values, combine conditions. Mastering them is your first step toward understanding algorithm complexity. Think of them as the action words that make your program actually do something instead of just sitting there holding data.
C# has several families of operators, and you'll use most of them every day.
Arithmetic Operators — Math Class
Comparison & Logical Operators
These operators ask yes-or-no questions and give back true or false.
==equal to (double equals — single=is assignment!)!=not equal to<,>,<=,>=— comparisons&&— AND (both must be true)||— OR (at least one must be true)!— NOT (flips true ↔ false)
Think of && as a strict parent ("You need BOTH clean room AND finished homework") and || as a chill parent ("Either one is fine").
Comparisons & Logic
The Ternary Operator & Null Tricks
The ternary operator ? : is a tiny if/else crammed into one line. It's perfect for simple choices:
condition ? valueIfTrue : valueIfFalse
C# also has two amazing null-safety operators:
??— null-coalescing: "Use this value, OR if it's null, use that backup value instead."?.— null-conditional: "Only access this property if the object isn't null. Otherwise, just give me null."is— pattern matching: checks the type AND can pull out the value in one step.