There is an array of difficulties in this program.
Code:
namespace scratchpad3
{
class Program
{
public static void Main()
{
aclass ac = new aclass();
// say I wonât return any method
}
}
public class aclass :IEnumerable
{
int[] star = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
public IEnumerator GetEnumerator()
{
//*****************What will happen if I declare the enumerator here??????????
foreach (int i in star)
{
Console.WriteLine(i);
Console.Read();
}
}
}
}
This program gives an ERROR message:-
Error 1 Using the generic type 'System.Collections.Generic.IEnumerable<T>' requires 1 type arguments C:\Users\lenovo\documents\visual studio 2010\Projects\scratchpad3\Program.cs 19 30 scratchpad3
But what if IF i WISH TO IMPLEMENT A NON-GENERIC TYPE:-
What I mean is that if i use IEnumerable instead of IEnumerable<T>
Even doing this i.e. putting IEnumerable<int> gives error message
ERROR
Error 1 'scratchpad3.aclass' does not implement interface member 'System.Collections.IEnumerable.GetEnumerator()'. 'scratchpad3.aclass.GetEnumerator()' cannot implement 'System.Collections.IEnumerable.GetEnumerator()' because it does not have the matching return type of 'System.Collections.IEnumerator'. C:\Users\lenovo\documents\visual studio 2010\Projects\scratchpad3\Program.cs 18 18 scratchpad3