Recall & Review
beginner
What is a Predicate delegate in C#?
A Predicate delegate is a special type of delegate that represents a method that takes one input parameter and returns a boolean value (true or false). It is often used to test conditions.
Click to reveal answer
beginner
How do you declare a Predicate delegate for integers?
You declare it as Predicate<int>. For example: Predicate<int> isEven = x => x % 2 == 0; This means isEven is a method that checks if an integer is even.
Click to reveal answer
beginner
What is the return type of a Predicate delegate method?
The return type is always bool. It returns true if the condition is met, otherwise false.
Click to reveal answer
intermediate
Can Predicate delegates be used with List<T> methods? Give an example.
Yes, Predicate delegates are commonly used with List<T> methods like Find or RemoveAll. Example: list.RemoveAll(x => x < 0); removes all negative numbers from the list.
Click to reveal answer
intermediate
What is the difference between Predicate<T> and Func?
Predicate<T> is a delegate specifically for methods that take one parameter and return bool. Func can do the same but is more general and can have multiple parameters. Predicate<T> is clearer when you want a boolean test.
Click to reveal answer
What does a Predicate delegate return?
✗ Incorrect
A Predicate delegate always returns a boolean value (true or false).
Which of these is a valid Predicate declaration for strings?
✗ Incorrect
Predicate must return a bool. s => s.Length == 0 returns true if the string is empty.
Which List<T> method commonly uses Predicate<T>?
✗ Incorrect
List.Find uses a Predicate to locate the first element matching the condition.
What parameter count does a Predicate delegate accept?
✗ Incorrect
Predicate delegates accept exactly one input parameter.
Which is a key difference between Predicate<T> and Func?
✗ Incorrect
Predicate takes one parameter and returns bool; Func can take multiple parameters and returns bool.
Explain what a Predicate delegate is and how it is used in C#.
Think about how you test conditions with a method that returns true or false.
You got /4 concepts.
Describe the difference between Predicate and Func delegates.
Focus on parameter count and clarity of intent.
You got /5 concepts.