Array and Collection Interfaces
The Array class
implements the interfaces IEnumerable,
ICollection, and IList for accessing and enumerating the elements of
the array. Because with a custom array a class is created that
derives from the abstract class Array,
you can use the methods and properties of the implemented
interfaces with an array variable.
IEnumerable
IEnumerable is an
interface that is used by the foreach
statement to iterate through the array. As this is a very special
feature, it will be discussed in the next section.
ICollection
The interface ICollection derives from the interface IEnumerable and has additional properties and
methods as shown in the following table. This interface is mainly
used to get the number of elements in a collection and for
synchronization.
IList
The IList
interface derives from the interface ICollection and defines additional properties and
methods. The major reason why the Array
class implements the IList interface is
that the IList interface defines the
Item property for accessing the elements
using an indexer. Many of the other IList members are implemented by the Array class by throwing a NotSupportedException, as these do not apply to
arrays. All the properties and methods of the IList interface are shown in the following
table.
|