Chapter 12. Collections
The most prevalent use of generics in any language is in the area of collections. Collections deal with sets of like objects and with managing those objects as a group. This chapter looks at the collection classes pro...
Primary Collection Classes
There are six key sets of collection classes, and they differ from each other in terms of how data is inserted, stored, and retrieved. Each generic class is located in the System.Collections.Generic namespace, and their ...
Introducing Collection Class Interfaces
The previous section examined the most common collection classes and the methods that are specific to them. This section delves into the collection-related interfaces in order to understand the common capabi...
Providing an Index Operator
The common collection interfaces provide much of the foundation for what members are needed when implementing custom collections. However, there is one more member: the index operator.
The index operator is a pair of...
Returning Null or an Empty Collection
When returning an array or collection, you must indicate that there are zero items by returning either null or a collection instance with no items. The better choice in general is to return a collection instan...
Iterators
Earlier, this chapter went into detail on the internals of the foreach loop. This section discusses how to use iterators to create your own implementation of the IEnumerator<T> and nongeneric IEnumerator interfaces for custom colle...
Summary
With the advent of generics in C# 2.0, the selection of which collection class to use will always favor generics over the nongeneric versions. In fact, C# 2.0 developers should consider the entire namespace of System.Collections as obsolet...
С 2009 года мы стали переводить структура сайта на различные языки. Сайт теперь будет содержать книги не только на английском языке, но также и на других европейских языках, в том числе и на Русском языке.