Hi All ,
I am new into C#, i want to use my class into foreach, I am using IEnumerable and IEnumerator interface in my class implementation, When I compile my code i got below mentioned error.
Error 'ConsoleApplica tion2.entries.M yenum' does not implement interface member 'System.Collect ions.IEnumerato r.Current' C:\Users\t_srid hardh1\Document s\Visual Studio 2008\Projects\C onsoleApplicati on2\ConsoleAppl ication2\Progra m.cs 32 22 ConsoleApplicat ion2
Please help anybody to resolve this.
Thanks
I am new into C#, i want to use my class into foreach, I am using IEnumerable and IEnumerator interface in my class implementation, When I compile my code i got below mentioned error.
Error 'ConsoleApplica tion2.entries.M yenum' does not implement interface member 'System.Collect ions.IEnumerato r.Current' C:\Users\t_srid hardh1\Document s\Visual Studio 2008\Projects\C onsoleApplicati on2\ConsoleAppl ication2\Progra m.cs 32 22 ConsoleApplicat ion2
Code:
using System;
using System.Collections;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
entries list = new entries();
foreach (int l in list)
{
Console.WriteLine(l);
}
}
}
class entries : IEnumerable
{
static int[] list = { 2, 3, 4, 5, 6 };
public IEnumerator GetEnumerator()
{
return new Myenum() ;
}
private class Myenum : IEnumerator
{
int index = -1;
public object current
{
get { return list[index]; }
}
public bool MoveNext()
{
if (++index >= list.Length)
return false;
else
return true;
}
public void Reset()
{
index = -1;
}
}
}
}
Thanks
Comment