System.Collections.IList Interface

Assembly: Mscorlib.dll
Namespace: System.Collections
Summary
Represents a collection of objects that can be individually accessed by index.
C# Syntax:
public interface IList : ICollection, IEnumerable
Remarks
IList is a descendant of the ICollection interface and is the base interface of all lists. IList implementations fall into three categories: read-only, fixed-size, variable-size. A read-only IList cannot be modified. A fixed-size IList does not allow the addition or removal of elements, but it allows the modification of existing elements. A variable-size IList allows the addition, removal and modification of elements.
See also:
System.Collections Namespace | ICollection

System.Collections.IList Member List:

Public Properties
IsFixedSize Read-only

When implemented by a class, gets a value indicating whether the IList has a fixed size.
IsReadOnly Read-only

When implemented by a class, gets a value indicating whether the IList is read-only.
Item Read-write

When implemented by a class, gets or sets the element at the specified index.
Public Methods
Add When implemented by a class, adds an item to the IList.
Clear When implemented by a class, removes all items from the IList.
Contains When implemented by a class, determines whether the IList contains a specific value.
IndexOf When implemented by a class, determines the index of a specific item in the IList.
Insert When implemented by a class, inserts an item to the IList at the specified position.
Remove When implemented by a class, removes the first occurrence of a specific object from the IList.
RemoveAt When implemented by a class, removes the IList item at the specified index.

Hierarchy:


System.Collections.IList Member Details

Property: IsFixedSize (read-only)
Summary
When implemented by a class, gets a value indicating whether the IList has a fixed size.
C# Syntax:
bool IsFixedSize {get;}
Remarks
A collection with a fixed size does not allow the addition or removal of elements after the collection is created, but it allows the modification of existing elements.

Return to top


Property: IsReadOnly (read-only)
Summary
When implemented by a class, gets a value indicating whether the IList is read-only.
C# Syntax:
bool IsReadOnly {get;}
Remarks
A collection that is read-only does not allow the addition, removal, or modification of elements after the collection is created.

Return to top


Property: Item (read-write)
Summary
When implemented by a class, gets or sets the element at the specified index.
C# Syntax:
object this[int index] {get; set;}
Parameters:

index

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

Exceptions
Exception Type Condition
ArgumentOutOfRangeException index is not a valid index in the IList.
NotSupportedException The property is set and the IList is read-only.
Remarks
This property provides the ability to access a specific element in the collection by using the following syntax: myCollection[index] .

Return to top


Method: Add(
   object value
)
Summary
When implemented by a class, adds an item to the IList.
C# Syntax:
int Add(
   object value
);
Parameters:

value

The Object to add to the IList.

Return Value:
The position into which the new element was inserted.
Exceptions
Exception Type Condition
NotSupportedException The IList is read-only.

-or-

The IList has a fixed size.

Return to top


Method: Clear()
Summary
When implemented by a class, removes all items from the IList.
C# Syntax:
void Clear();
Exceptions
Exception Type Condition
NotSupportedException The IList is read-only.
Remarks
Implementations of this method can vary in how they handle the ICollection.Count and the capacity of a collection. Typically, the count is set to zero. The capacity can be set to zero or a default value, or it can remain unchanged.

Return to top


Method: Contains(
   object value
)
Summary
When implemented by a class, determines whether the IList contains a specific value.
C# Syntax:
bool Contains(
   object value
);
Parameters:

value

The Object to locate in the IList.

Return Value:
true if the Object is found in the IList; otherwise, false.

Return to top


Method: IndexOf(
   object value
)
Summary
When implemented by a class, determines the index of a specific item in the IList.
C# Syntax:
int IndexOf(
   object value
);
Parameters:

value

The Object to locate in the IList.

Return Value:
The index of value if found in the list; otherwise, -1.

Return to top


Method: Insert(
   int index,
   object value
)
Summary
When implemented by a class, inserts an item to the IList at the specified position.
C# Syntax:
void Insert(
   int index,
   object value
);
Parameters:

index

The zero-based index at which value should be inserted.

value

The Object to insert into the IList.

Exceptions
Exception Type Condition
ArgumentOutOfRangeException index is not a valid index in the IList.
NotSupportedException The IList is read-only.

-or-

The IList has a fixed size.

Remarks
If index equals the number of items in the IList, then value is appended to the end.

In collections of contiguous elements, such as lists, the elements that follow the insertion point move down to accomodate the new element. If the collection is indexed, the indexes of the elements that are moved are also updated. This behavior does not apply to collections where elements are conceptually grouped into buckets, such as a hashtable.

Return to top


Method: Remove(
   object value
)
Summary
When implemented by a class, removes the first occurrence of a specific object from the IList.
C# Syntax:
void Remove(
   object value
);
Parameters:

value

The Object to remove from the IList.

Exceptions
Exception Type Condition
NotSupportedException The IList is read-only.

-or-

The IList has a fixed size.

Remarks
In collections of contiguous elements, such as lists, the elements that follow the removed element move up to occupy the vacated spot. If the collection is indexed, the indexes of the elements that are moved are also updated. This behavior does not apply to collections where elements are conceptually grouped into buckets, such as a hashtable.

Return to top


Method: RemoveAt(
   int index
)
Summary
When implemented by a class, removes the IList item at the specified index.
C# Syntax:
void RemoveAt(
   int index
);
Parameters:

index

The zero-based index of the item to remove.

Exceptions
Exception Type Condition
ArgumentOutOfRangeException index is not a valid index in the IList.
NotSupportedException The IList is read-only.

-or-

The IList has a fixed size.

Remarks
In collections of contiguous elements, such as lists, the elements that follow the removed element move up to occupy the vacated spot. If the collection is indexed, the indexes of the elements that are moved are also updated. This behavior does not apply to collections where elements are conceptually grouped into buckets, such as a hashtable.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.