Func <> delegate - Clarification

When an array is given:

 int[] a={1,3,4,5,67,8,899,56,12,33} 

and if I want to return even numbers using LINQ

 var q=a.where(p=>p%2==0) 

If I were to use C # 2.0 and strictly delegate func <>, how to solve it?

I tried:

 Func<int, bool> func = delegate(int val) { return val % 2 == 0; }; 

but I am confused how to bind the array "a" here.

+4
source share
2 answers
 int[] q = Array.FindAll<int>(a, delegate(int p) { return p % 2 == 0; }); 

(note that Predicate<int> , which is the same signature as Func<int,bool> )

+11
source

You can use Predicate and Array.FindAll .

 Predicate<int> func = delegate(int val) { return val % 2 == 0; }; Array.FindAll<int>(a, func); 
+4
source

All Articles