0
0
C Sharp (C#)programming~5 mins

Predicate delegate type in C Sharp (C#) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Aint
Bstring
Cbool
Dvoid
Which of these is a valid Predicate declaration for strings?
APredicate<string> isEmpty = s => s.Length == 0;
BPredicate<string> isEmpty = s => s + "";
CPredicate<string> isEmpty = s => Console.WriteLine(s);
DPredicate<string> isEmpty = s => s.Length;
Which List<T> method commonly uses Predicate<T>?
AAdd
BFind
CSort
DClear
What parameter count does a Predicate delegate accept?
AOne
BMultiple
CTwo
DZero
Which is a key difference between Predicate<T> and Func?
APredicate<T> returns int, Func<T, bool> returns bool
BPredicate<T> is a class, Func<T, bool> is a delegate
CPredicate<T> can only be used with strings
DPredicate<T> only takes one parameter, Func<T, bool> can take multiple
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.