#16 Enumerating Over Custom Class

To Enumerate over Custom Class,The Class must implement IEnumerable and must have method defined for GetEnumerator.

public class EmployeeArray:IEnumerable
 public int index;
 public Employee[] objarray;
public EmployeeArray(Employee[] Array ,int startindex )
 objarray = Array;
 index = startindex;
public IEnumerator GetEnumerator()
 for (int i = 0; i <;objarray.Length; i++)
 yield return objarray[(index+i) % objarray.Length];

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s