class int_filter
{
private delegate bool filter(int x);
private int[] inseq;
public int_filter()
{ }
public int[] interface_filteredint()
{
filter a = new filter(iseven);
return FileterArray(inseq, a);
}
public int_filter(int[] in_seq)
{
inseq = in_seq;
}
private int[] FileterArray(int[] input_seq, filter check_condition)
{
List<int> alist=new List<int>();
foreach(int x in input_seq)
{
if (check_condition(x))
alist.Add(x);
}
return alist.ToArray();
}
private bool iseven(int input_to_check)
{
if (input_to_check % 2 == 0)
return true;
else
return false;
}
}
Instantiating and testing the class.
{
private delegate bool filter(int x);
private int[] inseq;
public int_filter()
{ }
public int[] interface_filteredint()
{
filter a = new filter(iseven);
return FileterArray(inseq, a);
}
public int_filter(int[] in_seq)
{
inseq = in_seq;
}
private int[] FileterArray(int[] input_seq, filter check_condition)
{
List<int> alist=new List<int>();
foreach(int x in input_seq)
{
if (check_condition(x))
alist.Add(x);
}
return alist.ToArray();
}
private bool iseven(int input_to_check)
{
if (input_to_check % 2 == 0)
return true;
else
return false;
}
}
int[] anint={3,4,5,6,3,9,20,3,22,10,2};
int_filter atest=new int_filter(anint);
int[] int2 = atest.interface_filteredint();
foreach (int x in int2)
Console.WriteLine(x);
Console.ReadKey();
int_filter atest=new int_filter(anint);
int[] int2 = atest.interface_filteredint();
foreach (int x in int2)
Console.WriteLine(x);
Console.ReadKey();
0 comments:
Post a Comment