System.Collections.Generic.IList<T> Interface

public interface IList<T>: ICollection<T>, IEnumerable<T>

Base Types

This type implements ICollection<T> and IEnumerable<T>.

Assembly

mscorlib

Library

BCL

Summary

Represents a collection of objects that can be individually accessed by index.

Description

This interface is a descendant of the ICollection<T> interface and is the base interface of all generic lists.

See Also

System.Collections.Generic Namespace

Members

IList<T> Methods

IList<T>.IndexOf Method
IList<T>.Insert Method
IList<T>.RemoveAt Method

IList<T> Properties

IList<T>.Item Property


IList<T>.IndexOf Method

int IndexOf(T value)

Summary

Determines the index of a specific item in the current instance.

Parameters

value
The T to locate in the current instance.

Return Value

The index of value if found in the current instance; otherwise, -1.

Description

Implementations can vary in how they determine equality of objects; for example, List<T> uses the default comparer, whereas, System.Collections.Generic.Dictionary<T,U> allows the user to specify the IComparer<T> implementation to use for comparing keys.

See Also

System.Collections.Generic.IList<T> Interface, System.Collections.Generic Namespace

IList<T>.Insert Method

void Insert(int index, T value)

Summary

Inserts an item into the current instance at the specified position.

Parameters

index
A System.Int32 that specifies the zero-based index at which value is inserted.
value
The T to insert into the current instance.

Exceptions

Exception TypeCondition
ArgumentOutOfRangeExceptionindex is not a valid index in the current instance (i.e. is negative or greater than the number of elements in the current instance).

NotSupportedExceptionThe current instance is read-only.

Description

In collections of contiguous elements, such as lists, the elements that follow the insertion point have indices one more than previously, to accommodate the new element. If the collection is indexed, the indexes of the elements that are moved are also updated.

[Behaviors: If index equals the number of items in the System.Collections.Generic.IList<T>, then value is required to be appended to the end of the current instance.

]

See Also

System.Collections.Generic.IList<T> Interface, System.Collections.Generic Namespace

IList<T>.RemoveAt Method

void RemoveAt(int index)

Summary

Removes the item at the specified index of the current instance.

Parameters

index
A System.Int32 that specifies the zero-based index of the item to remove.

Exceptions

Exception TypeCondition
ArgumentOutOfRangeExceptionindex is not a valid index in the current instance.

NotSupportedExceptionThe current instance is read-only.

Description

In collections of contiguous elements, such as lists, the elements that follow the removed element have indices one less than previously. If the collection is indexed, the indexes of the elements that are moved are also updated.

See Also

System.Collections.Generic.IList<T> Interface, System.Collections.Generic Namespace

IList<T>.Item Property

T this[int index] { get; set; }

Summary

Gets or sets the element at the specified index in the current instance.

Parameters

index
The zero-based index of the element to get or set.

Property Value

The element at the specified index in the current instance.

Exceptions

Exception TypeCondition
ArgumentOutOfRangeExceptionindex is not a valid index in the current instance.

NotSupportedExceptionThe property is being set and the current instance is read-only.

Description

This property provides the ability to access a specific element in the collection by using some language-specific syntax.

See Also

System.Collections.Generic.IList<T> Interface, System.Collections.Generic Namespace