Collection interfaces


Jump to: navigation, search
Exam Prep. Guides
Exam 70-536 Study Guide

1. Types and collections

2. Process, threading,…
3. Embedding features
4. Serialization, I/O
5. .NET Security
6. Interop., reflection,…
7. Global., drawing, text

edit

As the name implies, a collection interface is an interface that provides the contract for a specific collection.

The .NET Framework provides a number of standard collection interfaces:

  • ICollection - Implemented by all collections
  • IList - Used by collections that can be indexed
  • IDictionary - For key/value-based collections such as Hashtable and SortedList
  • IComparer - Allows custom comparison for purpose of sorting and ordering
  • IEqualityComparer - Allows custom equality comparisons for collections that depend on equality but not order (like Hashtable)
  • IEnumerable - Provides the Enumerator for a collection
  • IEnumerator - Iterates over a collection and supports the foreach loop
  • IDictionaryEnumerator - An enumerator that enumerates a dictionary and add support for accessing the key and value of the current item.


Contents

ICollection

ICollection extends IEnumerable. It provides size and synchronization members in addition to enumeration.

IList

IList extends ICollection. It allows access to the items of a collection by their index.

IDictionary

IDictionary extends ICollection. It allows access to the items of a collection by their key.

IComparer

Allows custom comparison for the purposes of sorting and ordering.

IEqualityComparer

Allows custom equality comparisons for collections that depend on equality but not order (like Hashtable)

IKeyComparer

Replaced by IEqualityComparer since .NET 2.0 beta 2

IHashCodeProvider

Replaced by IEqualityComparer since .NET 2.0 beta 2

IEnumerable

IEnumerable allows a class to be enumerated using an enumerator. A class should inherit from IEnumerable in order to provide an enumerator through the GetEnumerator() method.

The foreach automatically calls GetEnumerator at the beginning of the loop and then uses that enumerator to go through the loop.

IEnumerator

An IEnumerator iterates over each item in a collection. It allows access to the current item and the ability to proceed to the next item. The foreach loop uses an enumerator to go through each item.

IDictionaryEnumerator

A IDictionaryEnumerator extends IEnumerator. It also adds support for accessing the key and value of the current item.


Previous_Page_.gif Next_Page_.gif


Personal tools