Posts

Showing posts with the label IEnumerable<T>

Donate

How To Implement IEnumerable<T> Interface In C# And VB.NET

Image
Hello, According to MSDN, IEnumerable<T> Interface exposes the enumerator, which supports a simple iteration over a collection of a specified type. Collections such as List<T> implements this interface. For this demo, I created a simple class that implements IEnumerable<string>. You can use concrete types instead of string or ordinary data types. Presented are two classes in different languages (C# and VB.NET) that implements the interface. Notice that in VB.NET, the yield functionality is applied in an Iterator function. C#.NET 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 namespace IEnumerableExample { class Program { static void Main( string [] args) { MessagingApp myObject = new MessagingApp(); foreach ( string item in myObject) { Console.WriteLine(item); } Console.

Donate