Notifications
Clear all
Topic starter 01/08/2025 11:42 pm
In .NET (especially C#), operators are symbols or keywords that perform operations on variables and values—things like arithmetic, comparison, and logic. Let’s break it down:
➕ Arithmetic Operators
+: addition-: subtraction*: multiplication/: division%: modulus (remainder)
int result = 7 + 3; // result is 10
⚖️ Comparison Operators
Used in conditions to compare values:
==: equal to!=: not equal to>: greater than<: less than>=: greater than or equal to<=: less than or equal to
bool isEqual = (5 == 5); // true
🔄 Logical Operators
Great for combining Boolean expressions:
&&: logical AND||: logical OR!: logical NOT
if (isSunny && isWarm) {
Console.WriteLine("Perfect weather!");
}
🧠 Bitwise Operators
Operate at the binary level:
&: AND|: OR^: XOR~: NOT<<: left shift>>: right shift
🧩 Assignment Operators
Set and modify variable values:
=: assign+=,-=,*=,/=,%=: shorthand for arithmetic + assignment
x += 5; // same as x = x + 5
🧪 Other Notables
??: null-coalescing operatorstring name = input ?? "Guest";?.: null-conditional operatoruser?.SendEmail(); // only calls if user is not null
Operators in .NET help make your logic expressive, concise, and powerful.