Challenge - 5 Problems
Property Patterns Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of nested property pattern matching
What is the output of this C# code using property patterns?
C Sharp (C#)
record Address(string City, string Country); record Person(string Name, Address Address); var person = new Person("Alice", new Address("Paris", "France")); string result = person is { Address: { City: "Paris" } } ? "Match" : "No match"; Console.WriteLine(result);
Attempts:
2 left
💡 Hint
Check how nested property patterns match inner properties.
✗ Incorrect
The pattern checks if the Address property has a City equal to "Paris". Since it does, the result is "Match".
❓ Predict Output
intermediate2:00remaining
Output of property pattern with discard
What will this C# code print?
C Sharp (C#)
record Product(string Name, decimal Price); var product = new Product("Book", 12.99m); string output = product is { Price: > 10, Name: _ } ? "Expensive" : "Cheap"; Console.WriteLine(output);
Attempts:
2 left
💡 Hint
The discard (_) means any Name is accepted.
✗ Incorrect
The pattern checks if Price is greater than 10 and ignores Name. Since Price is 12.99, it prints "Expensive".
❓ Predict Output
advanced2:00remaining
Output of property pattern with nested null property
What is the output of this code?
C Sharp (C#)
record Engine(int Horsepower); record Car(string Model, Engine? Engine); var car = new Car("Sedan", null); string result = car is { Engine: { Horsepower: > 200 } } ? "Powerful" : "Not powerful"; Console.WriteLine(result);
Attempts:
2 left
💡 Hint
Property patterns safely handle null nested properties.
✗ Incorrect
The pattern checks if Engine is not null and Horsepower > 200. Since Engine is null, it does not match and prints "Not powerful".
❓ Predict Output
advanced2:00remaining
Output of property pattern with multiple conditions
What will this code print?
C Sharp (C#)
record Employee(string Name, int Age, string Department); var emp = new Employee("John", 30, "HR"); string output = emp is { Age: (>= 18 and <= 65), Department: "HR" } ? "Eligible" : "Not eligible"; Console.WriteLine(output);
Attempts:
2 left
💡 Hint
Check the combined conditions with 'and' in property patterns.
✗ Incorrect
The pattern matches employees aged between 18 and 65 in the HR department. John meets both conditions, so output is "Eligible".
❓ Predict Output
expert3:00remaining
Output of property pattern with positional and property patterns combined
What is the output of this code?
C Sharp (C#)
record Point(int X, int Y) { public string Quadrant => (X, Y) switch { (> 0, > 0) => "First", (< 0, > 0) => "Second", (< 0, < 0) => "Third", (> 0, < 0) => "Fourth", _ => "Origin or axis" }; } var p = new Point(5, -3); string result = p is { X: > 0, Y: < 0 } ? p.Quadrant : "Unknown"; Console.WriteLine(result);
Attempts:
2 left
💡 Hint
Combine property patterns with positional pattern logic inside the property.
✗ Incorrect
The pattern matches X > 0 and Y < 0, which is the fourth quadrant. The Quadrant property returns "Fourth".