In This Article

SimpleReadOnlyCollection<T> Class

Provides a generic read-only collection.

public class SimpleReadOnlyCollection<T> : ReadOnlyCollection<T> where T : class
Type Parameters:
T -

The type of collection item.

Inheritance:
object ReadOnlyCollection<T> object
Derived:
DockContainerCollection DocumentWindowCollection TabbedMdiContainerCollection TabbedMdiWindowCollection ToolWindowCollection

Constructors

SimpleReadOnlyCollection()

Initializes an instance of the class.

public SimpleReadOnlyCollection()

SimpleReadOnlyCollection(List<T>)

Initializes an instance of the class as a wrapper for the specified list.

protected SimpleReadOnlyCollection(List<T> list)
Parameter Type Description
list List<T>

Properties

DefaultComparer

Defines the default comparer to be used when sorting. If an explicit default is not defined, an implicit default will be used.

protected virtual IComparer<T>? DefaultComparer { get; }

Property Value

IComparer<T>

Methods

FindIndex(int, int, Predicate<T>)

Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the first occurrence within the range of elements in the List<T> that starts at the specified index and contains the specified number of elements.

public int FindIndex(int startIndex, int count, Predicate<T> match)
Parameter Type Description
startIndex int

The zero-based starting index of the search.

count int

The number of elements in the section to search.

match Predicate<T>

The Predicate<T> delegate that defines the conditions of the element to search for.

Returns

int:

The zero-based index of the first occurrence of an element that matches the conditions defined by match, if found; otherwise, -1.

Exceptions

Type Condition
ArgumentNullException

match is null.

ArgumentOutOfRangeException
   <code class="paramref">startIndex</code> is outside the range of valid indexes for the <xref href="System.Collections.Generic.List%601" data-throw-if-not-resolved="false"></xref>.  

-or-

count is less than 0.

-or-

startIndex and count do not specify a valid section in the List<T>.

FindIndex(int, Predicate<T>)

Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the first occurrence within the range of elements in the List<T> that extends from the specified index to the last element.

public int FindIndex(int startIndex, Predicate<T> match)
Parameter Type Description
startIndex int

The zero-based starting index of the search.

match Predicate<T>

The Predicate<T> delegate that defines the conditions of the element to search for.

Returns

int:

The zero-based index of the first occurrence of an element that matches the conditions defined by match, if found; otherwise, -1.

Exceptions

Type Condition
ArgumentNullException

match is null.

ArgumentOutOfRangeException

startIndex is outside the range of valid indexes for the List<T>.

FindIndex(Predicate<T>)

Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the first occurrence within the entire List<T>.

public int FindIndex(Predicate<T> match)
Parameter Type Description
match Predicate<T>

The Predicate<T> delegate that defines the conditions of the element to search for.

Returns

int:

The zero-based index of the first occurrence of an element that matches the conditions defined by match, if found; otherwise, -1.

Exceptions

Type Condition
ArgumentNullException

match is null.

FindLastIndex(int, int, Predicate<T>)

Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the last occurrence within the range of elements in the List<T> that contains the specified number of elements and ends at the specified index.

public int FindLastIndex(int startIndex, int count, Predicate<T> match)
Parameter Type Description
startIndex int

The zero-based starting index of the backward search.

count int

The number of elements in the section to search.

match Predicate<T>

The Predicate<T> delegate that defines the conditions of the element to search for.

Returns

int:

The zero-based index of the last occurrence of an element that matches the conditions defined by match, if found; otherwise, -1.

Exceptions

Type Condition
ArgumentNullException

match is null.

ArgumentOutOfRangeException
   <code class="paramref">startIndex</code> is outside the range of valid indexes for the <xref href="System.Collections.Generic.List%601" data-throw-if-not-resolved="false"></xref>.  

-or-

count is less than 0.

-or-

startIndex and count do not specify a valid section in the List<T>.

FindLastIndex(int, Predicate<T>)

Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the last occurrence within the range of elements in the List<T> that extends from the first element to the specified index.

public int FindLastIndex(int startIndex, Predicate<T> match)
Parameter Type Description
startIndex int

The zero-based starting index of the backward search.

match Predicate<T>

The Predicate<T> delegate that defines the conditions of the element to search for.

Returns

int:

The zero-based index of the last occurrence of an element that matches the conditions defined by match, if found; otherwise, -1.

Exceptions

Type Condition
ArgumentNullException

match is null.

ArgumentOutOfRangeException

startIndex is outside the range of valid indexes for the List<T>.

ForEach(Action<T>)

Performs the specified action on each element of the List<T>.

public void ForEach(Action<T> action)
Parameter Type Description
action Action<T>

The Action<T> delegate to perform on each element of the List<T>.

Exceptions

Type Condition
ArgumentNullException

action is null.

InvalidOperationException

An element in the collection has been modified.

IndexOf(T, int)

Searches for the specified object and returns the zero-based index of the first occurrence within the range of elements in the List<T> that extends from the specified index to the last element.

public int IndexOf(T item, int index)
Parameter Type Description
item T

The object to locate in the List<T>. The value can be null for reference types.

index int

The zero-based starting index of the search. 0 (zero) is valid in an empty list.

Returns

int:

The zero-based index of the first occurrence of item within the range of elements in the List<T> that extends from index to the last element, if found; otherwise, -1.

Exceptions

Type Condition
ArgumentOutOfRangeException

index is outside the range of valid indexes for the List<T>.

IndexOf(T, int, int)

Searches for the specified object and returns the zero-based index of the first occurrence within the range of elements in the List<T> that starts at the specified index and contains the specified number of elements.

public int IndexOf(T item, int index, int count)
Parameter Type Description
item T

The object to locate in the List<T>. The value can be null for reference types.

index int

The zero-based starting index of the search. 0 (zero) is valid in an empty list.

count int

The number of elements in the section to search.

Returns

int:

The zero-based index of the first occurrence of item within the range of elements in the List<T> that starts at index and contains count number of elements, if found; otherwise, -1.

Exceptions

Type Condition
ArgumentOutOfRangeException
   <code class="paramref">index</code> is outside the range of valid indexes for the <xref href="System.Collections.Generic.List%601" data-throw-if-not-resolved="false"></xref>.  

-or-

count is less than 0.

-or-

index and count do not specify a valid section in the List<T>.

LastIndexOf(T)

Searches for the specified object and returns the zero-based index of the last occurrence within the entire List<T>.

public int LastIndexOf(T item)
Parameter Type Description
item T

The object to locate in the List<T>. The value can be null for reference types.

Returns

int:

The zero-based index of the last occurrence of item within the entire the List<T>, if found; otherwise, -1.

LastIndexOf(T, int)

Searches for the specified object and returns the zero-based index of the last occurrence within the range of elements in the List<T> that extends from the first element to the specified index.

public int LastIndexOf(T item, int index)
Parameter Type Description
item T

The object to locate in the List<T>. The value can be null for reference types.

index int

The zero-based starting index of the backward search.

Returns

int:

The zero-based index of the last occurrence of item within the range of elements in the List<T> that extends from the first element to index, if found; otherwise, -1.

Exceptions

Type Condition
ArgumentOutOfRangeException

index is outside the range of valid indexes for the List<T>.

Sort()

Sorts the elements in the entire List<T> using the default comparer.

public void Sort()

Exceptions

Type Condition
InvalidOperationException

The default comparer Default cannot find an implementation of the IComparable<T> generic interface or the IComparable interface for type T.

Sort(IComparer<T>)

Sorts the elements in the entire List<T> using the specified comparer.

public void Sort(IComparer<T> comparer)
Parameter Type Description
comparer IComparer<T>

The IComparer<T> implementation to use when comparing elements, or null to use the default comparer Default.

Exceptions

Type Condition
InvalidOperationException

comparer is null, and the default comparer Default cannot find implementation of the IComparable<T> generic interface or the IComparable interface for type T.

ArgumentException

The implementation of comparer caused an error during the sort. For example, comparer might not return 0 when comparing an item with itself.

Sort(Comparison<T>)

Sorts the elements in the entire List<T> using the specified Comparison<T>.

public void Sort(Comparison<T> comparison)
Parameter Type Description
comparison Comparison<T>

The Comparison<T> to use when comparing elements.

Exceptions

Type Condition
ArgumentNullException

comparison is null.

ArgumentException

The implementation of comparison caused an error during the sort. For example, comparison might not return 0 when comparing an item with itself.

Inherited Members

Extension Methods