Skip to main content

How To Implement IEnumerable Interface and yield Keyword

This sample shows how to create a list class which implements IEnumerable<int> and the yield keyword to enable foreach iteration over the contents of the list. Two properties are defined, one returning the odd numbers, the other returning the even numbers.

C# (40.7 KB)
4 Star
1,063 times
Add to favorites
E-mail Twitter Digg Facebook