Predicate vs Func in C#

In C#, a predicate is a delegate (a type that refers to a method) or a lambda expression that takes a single parameter and returns a Boolean value indicating whether the input meets certain criteria.

For example, the code below defines a predicate that tests if a given integer is even:

Predicate isEven = n => n % 2 == 0;
bool result = isEven(4); // true

A func, on the other hand, is a similar type of delegate or lambda expression, but it can take any number of input parameters and return any type of value.

For example, the code below defines a func that takes two integers and returns their sum:

Func sum= (x, y) => x + y;
int result = sum(3, 4); // 7

If you want to learn more about Func and Predicate in C# please check out the video tutorials below:

37. C# - Predicate
29. C# - Delegates

Image by vector_corp on Freepik


Enjoyed this post? Subscribe to my YouTube channel for more great content. Your support is much appreciated. Thank you!


Check out my Udemy profile for more great content and exclusive learning resources! Thank you for your support.
Ervis Trupja - Udemy



Enjoyed this blog post? Share it with your friends and help spread the word! Don't keep all this knowledge to yourself.