Recall & Review
beginner
What is a property pattern in C#?
A property pattern lets you check if an object has certain properties with specific values or conditions, making it easier to match complex data shapes in a clear way.
Click to reveal answer
beginner
How do you write a simple property pattern to check if a Point object has X equal to 0?
You write:
point is { X: 0 }. This means the object 'point' has a property 'X' with value 0.Click to reveal answer
intermediate
Can property patterns check nested properties? Give an example.
Yes. For example:
person is { Address: { City: "Paris" } } checks if 'person' has an 'Address' property whose 'City' is "Paris".Click to reveal answer
intermediate
What happens if a property in a property pattern is null or missing?
The pattern does not match. Property patterns require the property to exist and meet the condition; otherwise, the match fails.
Click to reveal answer
intermediate
How can you combine multiple property patterns in one check?
You can list multiple properties inside braces, like
obj is { Prop1: 5, Prop2: "hello" }, which means both conditions must be true.Click to reveal answer
What does the pattern
obj is { Name: "Alice" } check?✗ Incorrect
The pattern checks if the object has a property called Name with the value "Alice".
Can property patterns be used to check nested properties?
✗ Incorrect
Property patterns support nested properties by using nested braces, like { Address: { City: "Paris" } }.
What happens if a property in the pattern is missing on the object?
✗ Incorrect
If the property is missing, the pattern does not match because the condition cannot be verified.
How do you check multiple properties in one property pattern?
✗ Incorrect
You list multiple properties inside one set of braces separated by commas, like { Prop1: 1, Prop2: 2 }.
Which C# version introduced property patterns?
✗ Incorrect
Property patterns were introduced in C# 9 to improve pattern matching capabilities.
Explain what a property pattern is and how it helps in checking object properties.
Think about how you check if an object has certain values inside it.
You got /3 concepts.
Describe how to write a property pattern that checks multiple properties and nested properties.
Imagine checking a person's address city inside the person object.
You got /3 concepts.