#17 Yield KeyWord

The Yield Keyword Indicates that it is an Iterator. They are used with classes which implements  IEnumerable.

Yield Keyword indicates that you need not write an Explicit Class defining the GetEnumerator Method .In turn the compiler writes it for you.

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 )

Google photo

You are commenting using your Google 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