Data Structures
.NET provides various types of in-built data structures, such as the Array
, List
, and Dictionary
types. At the heart of all data structures are the IEnumerable
and ICollection
interfaces. Classes that implement these interfaces offer a way to enumerate through the individual elements and to manipulate their items. There is rarely a need to create your own classes that derive directly from these interfaces, as all the required functionality is covered by the built-in collection types, but it is worth knowing the key properties as they are heavily used throughout .NET.
The generic version of each collection type requires a single type parameter, which defines the type of elements that can be added to a collection, using the standard <T>
syntax of the generic types.
The IEnumerable
interface has a single property, that is, IEnumerator<T> GetEnumerator()
. This property returns a type that provides methods that allow the caller to iterate through the elements...