Posts

Showing posts with the label C# Comparison Operators

C# Comparison Operators

C# Comparison Operators Comparison operators in C# are used to compare values and return a boolean result (true or false). They are essential for making decisions and controlling the flow of your program. Here's a table of the common comparison operators: | Operator | Description | Example | |---|---|---| | == | Equal to | if (x == y) | | != | Not equal to | if (x != y) | | > | Greater than | if (x > y) | | < | Less than | if (x < y) | | >= | Greater than or equal to | if (x >= y) | | <= | Less than or equal to | if (x <= y) | Example: int x = 10; int y = 5; // Using comparison operators bool isEqual = x == y; // False bool isGreater = x > y; // True bool isLessOrEqual = x <= y; // False // Using comparison operators in an if statement if (x > y) {     Console.WriteLine("x is greater than y"); } else {     Console.WriteLine("x is not greater than y"); } Important Notes:  * Null Comparison: When comparing reference types (like str...