Thursday, July 1, 2010

IMPLEMENTING IENUMERABLE INTERFACE

IMPLEMENTING IENUMERABLE INTERFACE
Exposes the enumerator, which supports a simple iteration over a non-generic collection
Its works under System.Collections Namespace

IEnumerable, IEnumerator interfaces, which facilitates the iterative access in a custom collection
Implementation default method GetEnumerator of IEnumerable interface

Example Programe

using System;
using System.Collections;
class car:IEnumerable
{
private car[] carr;
public string name;
public car(string s)
{name=s;}
public car()
{
carr=new car[3];
carr[0]=new car("san");
carr[1]=new car("man");
carr[2]=new car("van");
}
public IEnumerator GetEnumerator()
{return carr.GetEnumerator();}
}
class enumInterface
{
public static void Main(string[] args)
{
car o=new car();
foreach(car c in o)
{
Console.WriteLine(c.name);
}
}
}

No comments:

Post a Comment