Advantage of Predicate <T> over Func <T, bool>?

Is there any value for using a predicate over a normal delegate? Taking the example below, I do not see.

Predicate<int> isEven = delegate(int x) { return x % 2 == 0; };
Console.WriteLine(isEven(1) + "\r\r");

Func<int, bool> isEven2 = delegate(int x) { return x % 2 == 0; };
Console.WriteLine(isEven(1) + "\r\r");
+5
source share
5 answers

They are almost the same. Predicate<T>is the type of delegate that has been added to the base class library for list methods and the Find () array. This was before LINQ when a more general family of delegates was introduced Func. You can even write your own delegate type and use it:

delegate bool IntPredicate(int x); 

static void Main()
{
   IntPredicate isEven = delegate(int x) {return x % 2 == 0;};
   Console.WriteLine(isEven(1) + "\r\r");
}
+5
source

- . , .Net framework 3.0. Predicate . , . , .Net, Func Action. void.

0

, Microsoft.

: List.FindAll Predicate.

, . Converter<int, bool>.

0

. , ( ) Func<T, TResult>, .

0

LINQ Func<T, bool> Predicate<T>.

0

All Articles