Complete the code to declare a Predicate delegate that checks if a number is positive.
Predicate<int> isPositive = [1];The Predicate delegate requires a method or lambda that returns true or false. Here, x => x > 0 correctly checks if the number is positive.
Complete the code to use the Predicate delegate to find if any number in the array is even.
int[] numbers = {1, 3, 5, 6};
bool hasEven = Array.Exists(numbers, [1]);The Array.Exists method uses a Predicate to check if any element matches the condition. x => x % 2 == 0 checks for even numbers.
Fix the error in the Predicate delegate that checks if a string is empty.
Predicate<string> isEmpty = s => s.[1] == 0;
Strings do not have an IsEmpty() method. Instead, checking s.Length == 0 tells if the string is empty. Here, the lambda uses s.Length property.
Fill both blanks to create a Predicate that checks if a number is between 10 and 20 (inclusive).
Predicate<int> isBetween = x => x [1] 10 && x [2] 20;
The predicate checks if x is greater than or equal to 10 and less than or equal to 20. So the correct operators are >= and <=.
Fill all three blanks to create a Predicate that checks if a string starts with 'A' and has length greater than 3.
Predicate<string> check = s => s.[1]("A") && s.[2] [3] 3;
The predicate uses StartsWith("A") to check the first letter, then checks if Length > 3 to ensure the string is longer than 3 characters.