Recall & Review
beginner
What is a relational pattern in C#?
A relational pattern in C# is a way to compare a value against a condition using relational operators like <, <=, >, >= inside a pattern matching expression.
Click to reveal answer
beginner
Which relational operators can be used in C# relational patterns?
You can use <, <=, >, and >= operators in relational patterns to check if a value is less than, less than or equal to, greater than, or greater than or equal to another value.
Click to reveal answer
intermediate
How do relational patterns improve code readability?
Relational patterns let you write conditions directly inside switch or if statements in a clear and concise way, avoiding extra variables or complex if-else chains.Click to reveal answer
beginner
Example: What does this C# code do? <br>
case >= 90: Console.WriteLine("Excellent"); break;This case matches when the value is greater than or equal to 90 and prints "Excellent". It uses a relational pattern to check the value directly.
Click to reveal answer
intermediate
Can relational patterns be combined with other patterns in C#?
Yes, relational patterns can be combined with logical patterns like 'and', 'or', and 'not' to create complex matching conditions.
Click to reveal answer
Which of these is a valid relational pattern in C#?
✗ Incorrect
Relational patterns use operators like >, <, >=, <=. Equality (==) is a constant pattern, not a relational pattern. '===' is not valid in C#.
What will this code print if value = 75?<br>
switch(value) { case >= 90: Console.WriteLine("A"); break; case >= 70: Console.WriteLine("B"); break; default: Console.WriteLine("C"); }✗ Incorrect
75 is not >= 90, so first case fails. 75 is >= 70, so it prints "B".
Can you use relational patterns inside an if statement in C#?
✗ Incorrect
Relational patterns can be used with 'is' in if statements, like 'if (x is > 10)'.
Which C# version introduced relational patterns?
✗ Incorrect
Relational patterns were introduced in C# 9.0.
What does this pattern mean? 'case < 0:'
✗ Incorrect
The pattern matches any value less than zero.
Explain what relational patterns are and how they are used in C#.
Think about how you compare numbers in conditions.
You got /3 concepts.
Describe how relational patterns can be combined with logical patterns in C#.
Consider how you join multiple conditions in if statements.
You got /3 concepts.