VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/predicate-delegate-in-c-sharp/

⇱ Predicate Delegate in C# - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Predicate Delegate in C#

Last Updated : 31 Oct, 2025

In C#, a Predicate is a built-in delegate type used to represent a method that takes one input parameter and returns a boolean value (true or false). It is widely used for testing conditions, especially in filtering data with collections.

Example: Predicate with a Lambda Expression

Output:

True

False

The Predicate<int> delegate takes an integer and checks if it is even. It returns true for 10 and false for 7.

Syntax

public delegate bool Predicate<in T>(T obj);

  • Always takes exactly one parameter of type T.
  • Always returns a bool (true or false).

Key Points

  • Predicate delegates always return a bool.
  • Useful for conditions, filtering and validation.
  • Frequently used with collection methods like Find, FindAll, Exists, RemoveAll.
  • Provides cleaner, reusable and testable condition logic.

Example 1: Predicate with a Named Method

Output:

True

False

The method CheckPositive matches the Predicate signature (takes one parameter, returns bool). So it can be directly assigned to a Predicate delegate.

Example 2: Predicate with Collections

Predicates are very useful in collection methods like List<T>.Find, FindAll, Exists and RemoveAll.

Output:

First Even: 2

All Even Numbers:

2

4

6

  • Find -> Returns the first element matching the condition.
  • FindAll -> Returns all elements matching the condition.
  • The Predicate makes it easy to pass conditions as reusable delegates.

Example 3: Predicate with Custom Objects

Output:

Passed Students:

Alice - 85

Charlie - 60

Here the Predicate checks whether a student has marks greater than or equal to 50. The FindAll method uses this Predicate to return only passing students.

Comment
Article Tags:
Article Tags:

Explore