O'Reilly logo

.NET Programming: A Practical Guide Using C# by Pradeep Tapadiya

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Enumeration

A common programming task is to iterate over a collection of elements. For example, a GUI application may be required to iterate over all the open documents to close them on exit or a database reader application may wish to iterate over the set of records obtained as a result of an SQL query to the database.

In Chapter 2, we saw that in C# one can iterate over an array using the foreach keyword. However, there are forms of collections that cannot always be represented as arrays. Wouldn't it be nice if you could use foreach on your own collection type that is not an array?

Under .NET this capability is achieved using enumeration. Enumeration is defined as a mechanism for providing a simple iteration over a set of elements. Any datatype ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required