Skip to content

28. Interfaces ICollection and ICollection<T>

February 7, 2011

The Interface ICollection is the base interface of the classes in the namespace System.Collections and has the following members:

  • int Count
    Gets the number of elements contained in the collection.
  • void CopyTo(Array array, int index)
    Copies the elements of the collection into an array starting at a particular index.

The interface ICollection<T> is the base interface of all classes in the namespace System.Collections.Generic and contains the following members:

  • int Count
  • bool IsReadOnly
    gets a value indicating whether the collection is read only.
  • int Add(T item)
    adds an item to the end of the collection and returns the number of elements of a collection upon an insertion.
  • void Clear()
    removes all items from the collection.
  • bool Contains(T item)
    determines whether the collection contains a specific value.
  • void CopyTo(T[] array,int index)
    copies the elements of the collection to an array, starting at a particular index.
  • void Remove(T item)
    removes the first occurrence of a specific object from the collection. The size of the list decreases automatically.

The interface ICollection expands IEnumerable; IDictionary and IList are more specialised interfaces that expand ICollection.
An implementation of IDictionary is a collection of key/value pairs, equivalent to the class Hashtable. An implementation of IList is a collection of objects whose members are accessible by index, like the class ArrayList.

Happy Programming! =)

Advertisements

From → OOP

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: