Complete the code to check if the object has a property Age equal to 30 using a property pattern.
if (person is { Age: [1] }) { Console.WriteLine("Age is 30"); }
The property pattern matches the property Age with the value 30.
Complete the code to check if the object has a Name property equal to "Alice" using a property pattern.
if (person is { Name: [1] }) { Console.WriteLine("Name is Alice"); }
The property pattern matches the Name property with the string value "Alice". Strings must be in quotes.
Fix the error in the property pattern to correctly check if the object has a property IsActive set to true.
if (user is { IsActive: [1] }) { Console.WriteLine("User is active"); }
The boolean value true is used without quotes and with lowercase t in C#.
Fill both blanks to check if the object has properties Age greater than 18 and Name equal to "John" using property patterns.
if (person is { Age: [1], Name: [2] }) { Console.WriteLine("Adult named John"); }
The pattern checks if Age is greater than 18 and Name equals "John".
Fill all three blanks to create a property pattern that matches an object with Age less than 65, Name starting with 'A', and IsActive true.
if (employee is { Age: [1], Name: [2], IsActive: [3] }) { Console.WriteLine("Active employee with name starting with A and age under 65"); }
var and when for string pattern.The pattern uses a relational pattern for Age, a property pattern with a when clause for Name, and matches IsActive to true.