Calling the Filter Method with an Anonymous Method : Filter : LINQ C# Source Code


Custom Search

C# Source Code » LINQ » Filter »

 

Calling the Filter Method with an Anonymous Method








    
 
using System;
using System.Collections;

public delegate bool IntFilter(int i);

public class MainClass {
    public static int[] FilterArrayOfInts(int[] ints, IntFilter filter) {
        ArrayList aList = new ArrayList();
        foreach (int i in ints) {
            if (filter(i)) {
                aList.Add(i);
            }
        }
        return ((int[])aList.ToArray(typeof(int)));
    }
    public static void Main() {

        int[] nums = { 1, 2, 3, 4, 5, 6};

        int[] oddNums = FilterArrayOfInts(nums, delegate(int i) { return ((i & 1) == 1); });

        foreach (int i in oddNums)
            Console.WriteLine(i);
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo LINQ
» Filter