Remove all with delegate in CSharp
Description
The following code shows how to remove all with delegate.
Example
/*from w ww .j a va 2s . c om*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
class Primes
{
static void Main()
{
List<int> candidates = new List<int>();
for (int i=2; i <= 50; i++)
{
candidates.Add(i);
}
candidates.ForEach (delegate(int prime)
{ Console.WriteLine(prime); }
);
for (int factor=2; factor <= 10; factor++)
{
candidates.RemoveAll (delegate(int x)
{ return x>factor && x%factor==0; }
);
}
candidates.ForEach (delegate(int prime)
{ Console.WriteLine(prime); }
);
}
}
The code above generates the following result.