System.Collections.IList Interface

public interface IList : ICollection, IEnumerable

Base Types

This type implements ICollection and IEnumerable.

Assembly

mscorlib

Library

BCL

Summary

Implemented by classes that support a collection of objects that can be individually indexed.

Description

[Note: IList implementations fall into three categories: read-only, fixed-size, variable-size. A read-only list cannot be modified. A fixed-size list allows the modification of existing elements, but does not allow the addition or removal of elements. A variable-size list allows the modification, addition, and removal of elements.]

Attributes

DefaultMemberAttribute("Item")

See Also

System.Collections Namespace

Members

IList Methods

IList.Add Method
IList.Clear Method
IList.Contains Method
IList.IndexOf Method
IList.Insert Method
IList.Remove Method
IList.RemoveAt Method

IList Properties

IList.IsFixedSize Property
IList.IsReadOnly Property
IList.Item Property


IList.Add Method

int Add(object value);

Summary

Adds an item to the current instance.

Parameters

value
The Object to add to the current instance.

Return Value

A Int32 containing the index of the current instance into which the new element was inserted.

Exceptions

Exception TypeCondition
NotSupportedExceptionThe current instance is read-only or has a fixed size.

Description

[Behaviors: As described above.]

[Usage: Use the System.Collections.IList.Add(System.Object) method to add another element to the current instance. The index into which that element is added is implementation-dependent. ]

See Also

System.Collections.IList Interface, System.Collections Namespace

IList.Clear Method

void Clear();

Summary

Removes all items from the current instance.

Exceptions

Exception TypeCondition
NotSupportedExceptionThe current instance is read-only.

Description

[Behaviors: As described above.]

[Overrides: Implementations of this method can vary in how a call to this method affects the capacity of a list. Typically, the count is set to zero. The capacity can be set to zero, some default, or remain unchanged.]

[Usage: Use this method to delete all values from the current instance.]

See Also

System.Collections.IList Interface, System.Collections Namespace

IList.Contains Method

bool Contains(object value);

Summary

Determines whether the current instance contains a specific value.

Parameters

value
The Object to locate in the current instance.

Return Value

true if the Object is found in the current instance; otherwise, false .

Description

[Behaviors: As described above.]

[Usage: Use the System.Collections.IList.Contains(System.Object) method to determine if a particular Object is an element of the current instance.]

See Also

System.Collections.IList Interface, System.Collections Namespace

IList.IndexOf Method

int IndexOf(object value);

Summary

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

Parameters

value
The Object to locate in the current instance.

Return Value

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

Description

[Behaviors: As described above.]

[Overrides: The default implementations of this method use System.Object.Equals(System.Object) to search for value in the current instance.]

[Usage: Use System.Collections.IList.IndexOf(System.Object) to determine if a Object is contained in the current instance and, if it is contained, its index in the current instance.]

See Also

System.Collections.IList Interface, System.Collections Namespace

IList.Insert Method

void Insert(int index, object value);

Summary

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

Parameters

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

Exceptions

Exception TypeCondition
ArgumentOutOfRangeExceptionindex is not a valid index in the current instance (i.e. is greater than the number of elements in the current instance).
NotSupportedExceptionThe current instance is read-only or has a fixed size.

Description

[Behaviors: If index equals the number of items in the IList, then value is required to be appended to the end of the current instance. ]

[Usage: Use System.Collections.IList.Insert(System.Int32,System.Object) to place a new element into a specific position in the current instance.]

See Also

System.Collections.IList Interface, System.Collections Namespace

IList.Remove Method

void Remove(object value);

Summary

Removes the first occurrence of a specified Object from the current instance.

Parameters

value
The Object to remove from the current instance.

Exceptions

Exception TypeCondition
NotSupportedExceptionThe current instance is read-only or has a fixed size.

Description

[Behaviors: As described above.

In addition, if value is null or is not found in the current instance, it is required that no exception be thrown and the current instance remain unchanged.

]

[Overrides: The default implementations of this method use System.Object.Equals(System.Object) to search for value in the current instance.]

[Usage: Use System.Collections.IList.Remove(System.Object) to delete a specified Object from the current instance.]

See Also

System.Collections.IList Interface, System.Collections Namespace

IList.RemoveAt Method

void RemoveAt(int index);

Summary

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

Parameters

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

Exceptions

Exception TypeCondition
ArgumentOutOfRangeExceptionindex is not a valid index in current instance.
NotSupportedExceptionThe current instance is read-only or has a fixed size.

Description

[Behaviors: As described above.]

[Usage: Use System.Collections.IList.RemoveAt(System.Int32) to delete a specified Object from the current instance.]

See Also

System.Collections.IList Interface, System.Collections Namespace

IList.IsFixedSize Property

bool IsFixedSize { get; }

Summary

Gets a Boolean value indicating whether the current instance has a fixed size.

Property Value

true if the current instance has a fixed size; otherwise, false .

Description

This property is read-only.

[Note: A collection with a fixed size does not allow the addition or removal of elements, but it allows the modification of existing elements.]

[Behaviors: Any method that adds or removes an element of a collection is required to check the value of this property for the particular collection before adding or removing elements. If the value of this property is false , any attempt to add or remove an element of the current instance is required to throw a NotSupportedException.]

[Default: The default of this property is false .]

[Overrides: Override this property, setting the value to true , in order to prevent the addition or removal of elements in the current instance.]

[Usage: Use System.Collections.IList.IsFixedSize to secure the current instance from modification from methods, such as System.Collections.IList.Add(System.Object) and System.Collections.IList.Remove(System.Object), which add or remove elements from a list.]

See Also

System.Collections.IList Interface, System.Collections Namespace

IList.IsReadOnly Property

bool IsReadOnly { get; }

Summary

Gets a value indicating whether the current instance is read-only.

Property Value

true if the current instance is read-only; otherwise, false .

Description

This property is read-only.

[Note: A collection that is read-only does not allow the modification, addition, or removal of elements.]

[Behaviors: Any method that modifies, adds, or removes an element of a collection is required to check the value of this property for the particular collection before executing. If the value of this property is false , any attempt to modify, add, or remove an element of the current instance is required to throw a NotSupportedException. ]

[Default: The default of this property is false .]

[Overrides: Override this property, setting the value to true , in order to prevent the modification, addition, or removal of elements in the current instance.]

[Usage: Use System.Collections.IList.IsReadOnly to secure the current instance from modification from methods, such as System.Collections.IList.Add(System.Object) and System.Collections.IList.Remove(System.Object), which modify, add, or remove elements from a list.]

See Also

System.Collections.IList Interface, System.Collections Namespace

IList.Item Property

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

Summary

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

Parameters

index
A Int32 that specifies 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

[Behaviors: As described above.]

[Usage: Use this property for subscript indexing for the current instance in the following form: myCollection[index]. ]

See Also

System.Collections.IList Interface, System.Collections Namespace