Skip to main content
ReadOnlyCollection Class
 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Provides the base class for a generic read-only collection.

Namespace:   System.Collections.ObjectModel
Assembly:  mscorlib (in mscorlib.dll)


[SerializableAttribute]
[ComVisibleAttribute(false)]
public class ReadOnlyCollection<T> : IList<T>, ICollection<T>, 
	IEnumerable<T>, IEnumerable, IList, ICollection, IReadOnlyList<T>, 
	IReadOnlyCollection<T>
generic<typename T>
[SerializableAttribute]
[ComVisibleAttribute(false)]
public ref class ReadOnlyCollection : IList<T>, ICollection<T>, 
	IEnumerable<T>, IEnumerable, IList, ICollection, IReadOnlyList<T>, 
	IReadOnlyCollection<T>
[<SerializableAttribute>]
[<ComVisibleAttribute(false)>]
type ReadOnlyCollection<'T> = 
    class
        interface IList<'T>
        interface ICollection<'T>
        interface IEnumerable<'T>
        interface IEnumerable
        interface IList
        interface ICollection
        interface IReadOnlyList<'T>
        interface IReadOnlyCollection<'T>
    end
<SerializableAttribute>
<ComVisibleAttribute(False)>
Public Class ReadOnlyCollection(Of T)
	Implements IList(Of T), ICollection(Of T), IEnumerable(Of T), IEnumerable,
	IList, ICollection, IReadOnlyList(Of T), IReadOnlyCollection(Of T)

Type Parameters

T

The type of elements in the collection.

NameDescription
System_CAPS_pubmethod ReadOnlyCollection

Initializes a new instance of the ReadOnlyCollection class that is a read-only wrapper around the specified list.

NameDescription
System_CAPS_pubproperty

Gets the number of elements contained in the ReadOnlyCollection instance.

System_CAPS_pubproperty

Gets the element at the specified index.

System_CAPS_protproperty

Returns the IList that the ReadOnlyCollection wraps.

NameDescription
System_CAPS_pubmethod Contains

Determines whether an element is in the ReadOnlyCollection.

System_CAPS_pubmethod CopyTo

Copies the entire ReadOnlyCollection to a compatible one-dimensional Array, starting at the specified index of the target array.

System_CAPS_pubmethod Equals

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethod Finalize

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethod GetEnumerator

Returns an enumerator that iterates through the ReadOnlyCollection.

System_CAPS_pubmethod GetHashCode

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethod GetType

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethod IndexOf

Searches for the specified object and returns the zero-based index of the first occurrence within the entire ReadOnlyCollection.

System_CAPS_protmethod MemberwiseClone

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethod ToString

Returns a string that represents the current object.(Inherited from Object.)

NameDescription
System_CAPS_pubinterface System_CAPS_privmethod ICollectionAdd

Adds an item to the ICollection. This implementation always throws NotSupportedException.

System_CAPS_pubinterface System_CAPS_privmethod ICollectionClear

Removes all items from the ICollection. This implementation always throws NotSupportedException.

System_CAPS_pubinterface System_CAPS_privmethod ICollectionRemove

Removes the first occurrence of a specific object from the ICollection. This implementation always throws NotSupportedException.

System_CAPS_pubinterface System_CAPS_privmethod IListInsert

Inserts an item to the IList at the specified index. This implementation always throws NotSupportedException.

System_CAPS_pubinterface System_CAPS_privmethod IListRemoveAt

Removes the IList item at the specified index. This implementation always throws NotSupportedException.

System_CAPS_pubinterface System_CAPS_privmethod ICollectionCopyTo

Copies the elements of the ICollection to an Array, starting at a particular Array index.

System_CAPS_pubinterface System_CAPS_privmethod IEnumerableGetEnumerator

Returns an enumerator that iterates through a collection.

System_CAPS_pubinterface System_CAPS_privmethod IListAdd

Adds an item to the IList. This implementation always throws NotSupportedException.

System_CAPS_pubinterface System_CAPS_privmethod IListClear

Removes all items from the IList. This implementation always throws NotSupportedException.

System_CAPS_pubinterface System_CAPS_privmethod IListContains

Determines whether the IList contains a specific value.

System_CAPS_pubinterface System_CAPS_privmethod IListIndexOf

Determines the index of a specific item in the IList.

System_CAPS_pubinterface System_CAPS_privmethod IListInsert

Inserts an item to the IList at the specified index. This implementation always throws NotSupportedException.

System_CAPS_pubinterface System_CAPS_privmethod IListRemove

Removes the first occurrence of a specific object from the IList. This implementation always throws NotSupportedException.

System_CAPS_pubinterface System_CAPS_privmethod IListRemoveAt

Removes the IList item at the specified index. This implementation always throws NotSupportedException.

System_CAPS_pubinterface System_CAPS_privproperty

Gets a value indicating whether the ICollection is read-only.

System_CAPS_pubinterface System_CAPS_privproperty

Gets the element at the specified index. An NotSupportedException occurs if you try to set the item at the specified index.

System_CAPS_pubinterface System_CAPS_privproperty

Gets a value indicating whether access to the ICollection is synchronized (thread safe).

System_CAPS_pubinterface System_CAPS_privproperty

Gets an object that can be used to synchronize access to the ICollection.

System_CAPS_pubinterface System_CAPS_privproperty

Gets a value indicating whether the IList has a fixed size.

System_CAPS_pubinterface System_CAPS_privproperty

Gets a value indicating whether the IList is read-only.

System_CAPS_pubinterface System_CAPS_privproperty

Gets the element at the specified index. A NotSupportedException occurs if you try to set the item at the specified index.

NameDescription
System_CAPS_pubmethod Aggregate

Overloaded. Applies an accumulator function over a sequence.(Defined by Enumerable.)

System_CAPS_pubmethod Aggregate

Overloaded. Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value.(Defined by Enumerable.)

System_CAPS_pubmethod Aggregate

Overloaded. Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value, and the specified function is used to select the result value.(Defined by Enumerable.)

System_CAPS_pubmethod All

Determines whether all elements of a sequence satisfy a condition.(Defined by Enumerable.)

System_CAPS_pubmethod Any

Overloaded. Determines whether a sequence contains any elements.(Defined by Enumerable.)

System_CAPS_pubmethod Any

Overloaded. Determines whether any element of a sequence satisfies a condition.(Defined by Enumerable.)

System_CAPS_pubmethod Append

Appends a value to the end of the sequence.(Defined by Enumerable.)

System_CAPS_pubmethod AsEnumerable

Returns the input typed as IEnumerable.(Defined by Enumerable.)

System_CAPS_pubmethod AsParallel

Overloaded. Enables parallelization of a query.(Defined by ParallelEnumerable.)

System_CAPS_pubmethod AsParallel

Overloaded. Enables parallelization of a query.(Defined by ParallelEnumerable.)

System_CAPS_pubmethod AsQueryable

Overloaded. Converts an IEnumerable to an IQueryable.(Defined by Queryable.)

System_CAPS_pubmethod AsQueryable

Overloaded. Converts a generic IEnumerable to a generic IQueryable.(Defined by Queryable.)

System_CAPS_pubmethod Average

Overloaded. Computes the average of a sequence of Decimal values that are obtained by invoking a transform function on each element of the input sequence.(Defined by Enumerable.)

System_CAPS_pubmethod Average

Overloaded. Computes the average of a sequence of Double values that are obtained by invoking a transform function on each element of the input sequence.(Defined by Enumerable.)

System_CAPS_pubmethod Average

Overloaded. Computes the average of a sequence of Int32 values that are obtained by invoking a transform function on each element of the input sequence.(Defined by Enumerable.)

System_CAPS_pubmethod Average

Overloaded. Computes the average of a sequence of Int64 values that are obtained by invoking a transform function on each element of the input sequence.(Defined by Enumerable.)

System_CAPS_pubmethod Average

Overloaded. Computes the average of a sequence of nullable Decimal values that are obtained by invoking a transform function on each element of the input sequence.(Defined by Enumerable.)

System_CAPS_pubmethod Average

Overloaded. Computes the average of a sequence of nullable Double values that are obtained by invoking a transform function on each element of the input sequence.(Defined by Enumerable.)

System_CAPS_pubmethod Average

Overloaded. Computes the average of a sequence of nullable Int32 values that are obtained by invoking a transform function on each element of the input sequence.(Defined by Enumerable.)

System_CAPS_pubmethod Average

Overloaded. Computes the average of a sequence of nullable Int64 values that are obtained by invoking a transform function on each element of the input sequence.(Defined by Enumerable.)

System_CAPS_pubmethod Average

Overloaded. Computes the average of a sequence of nullable Single values that are obtained by invoking a transform function on each element of the input sequence.(Defined by Enumerable.)

System_CAPS_pubmethod Average

Overloaded. Computes the average of a sequence of Single values that are obtained by invoking a transform function on each element of the input sequence.(Defined by Enumerable.)

System_CAPS_pubmethod Cast

Casts the elements of an IEnumerable to the specified type.(Defined by Enumerable.)

System_CAPS_pubmethod Concat

Concatenates two sequences.(Defined by Enumerable.)

System_CAPS_pubmethod Contains

Overloaded. Determines whether a sequence contains a specified element by using the default equality comparer.(Defined by Enumerable.)

System_CAPS_pubmethod Contains

Overloaded. Determines whether a sequence contains a specified element by using a specified IEqualityComparer.(Defined by Enumerable.)

System_CAPS_pubmethod Count

Overloaded. Returns the number of elements in a sequence.(Defined by Enumerable.)

System_CAPS_pubmethod Count

Overloaded. Returns a number that represents how many elements in the specified sequence satisfy a condition.(Defined by Enumerable.)

System_CAPS_pubmethod DefaultIfEmpty

Overloaded. Returns the elements of the specified sequence or the type parameter's default value in a singleton collection if the sequence is empty.(Defined by Enumerable.)

System_CAPS_pubmethod DefaultIfEmpty

Overloaded. Returns the elements of the specified sequence or the specified value in a singleton collection if the sequence is empty.(Defined by Enumerable.)

System_CAPS_pubmethod Distinct

Overloaded. Returns distinct elements from a sequence by using the default equality comparer to compare values.(Defined by Enumerable.)

System_CAPS_pubmethod Distinct

Overloaded. Returns distinct elements from a sequence by using a specified IEqualityComparer to compare values.(Defined by Enumerable.)

System_CAPS_pubmethod ElementAt

Returns the element at a specified index in a sequence.(Defined by Enumerable.)

System_CAPS_pubmethod ElementAtOrDefault

Returns the element at a specified index in a sequence or a default value if the index is out of range.(Defined by Enumerable.)

System_CAPS_pubmethod Except

Overloaded. Produces the set difference of two sequences by using the default equality comparer to compare values.(Defined by Enumerable.)

System_CAPS_pubmethod Except

Overloaded. Produces the set difference of two sequences by using the specified IEqualityComparer to compare values.(Defined by Enumerable.)

System_CAPS_pubmethod First

Overloaded. Returns the first element of a sequence.(Defined by Enumerable.)

System_CAPS_pubmethod First

Overloaded. Returns the first element in a sequence that satisfies a specified condition.(Defined by Enumerable.)

System_CAPS_pubmethod FirstOrDefault

Overloaded. Returns the first element of a sequence, or a default value if the sequence contains no elements.(Defined by Enumerable.)

System_CAPS_pubmethod FirstOrDefault

Overloaded. Returns the first element of the sequence that satisfies a condition or a default value if no such element is found.(Defined by Enumerable.)

System_CAPS_pubmethod GroupBy

Overloaded. Groups the elements of a sequence according to a specified key selector function.(Defined by Enumerable.)

System_CAPS_pubmethod GroupBy

Overloaded. Groups the elements of a sequence according to a specified key selector function and compares the keys by using a specified comparer.(Defined by Enumerable.)

System_CAPS_pubmethod GroupBy

Overloaded. Groups the elements of a sequence according to a specified key selector function and projects the elements for each group by using a specified function.(Defined by Enumerable.)

System_CAPS_pubmethod GroupBy

Overloaded. Groups the elements of a sequence according to a key selector function. The keys are compared by using a comparer and each group's elements are projected by using a specified function.(Defined by Enumerable.)

System_CAPS_pubmethod GroupBy

Overloaded. Groups the elements of a sequence according to a specified key selector function and creates a result value from each group and its key.(Defined by Enumerable.)

System_CAPS_pubmethod GroupBy

Overloaded. Groups the elements of a sequence according to a specified key selector function and creates a result value from each group and its key. The keys are compared by using a specified comparer.(Defined by Enumerable.)

System_CAPS_pubmethod GroupBy

Overloaded. Groups the elements of a sequence according to a specified key selector function and creates a result value from each group and its key. The elements of each group are projected by using a specified function.(Defined by Enumerable.)

System_CAPS_pubmethod GroupBy

Overloaded. Groups the elements of a sequence according to a specified key selector function and creates a result value from each group and its key. Key values are compared by using a specified comparer, and the elements of each group are projected by using a specified function.(Defined by Enumerable.)

System_CAPS_pubmethod GroupJoin

Overloaded. Correlates the elements of two sequences based on equality of keys and groups the results. The default equality comparer is used to compare keys.(Defined by Enumerable.)

System_CAPS_pubmethod GroupJoin

Overloaded. Correlates the elements of two sequences based on key equality and groups the results. A specified IEqualityComparer is used to compare keys.(Defined by Enumerable.)

System_CAPS_pubmethod Intersect

Overloaded. Produces the set intersection of two sequences by using the default equality comparer to compare values.(Defined by Enumerable.)

System_CAPS_pubmethod Intersect

Overloaded. Produces the set intersection of two sequences by using the specified IEqualityComparer to compare values.(Defined by Enumerable.)

System_CAPS_pubmethod Join

Overloaded. Correlates the elements of two sequences based on matching keys. The default equality comparer is used to compare keys.(Defined by Enumerable.)

System_CAPS_pubmethod Join

Overloaded. Correlates the elements of two sequences based on matching keys. A specified IEqualityComparer is used to compare keys.(Defined by Enumerable.)

System_CAPS_pubmethod Last

Overloaded. Returns the last element of a sequence.(Defined by Enumerable.)

System_CAPS_pubmethod Last

Overloaded. Returns the last element of a sequence that satisfies a specified condition.(Defined by Enumerable.)

System_CAPS_pubmethod LastOrDefault

Overloaded. Returns the last element of a sequence, or a default value if the sequence contains no elements.(Defined by Enumerable.)

System_CAPS_pubmethod LastOrDefault

Overloaded. Returns the last element of a sequence that satisfies a condition or a default value if no such element is found.(Defined by Enumerable.)

System_CAPS_pubmethod LongCount

Overloaded. Returns an Int64 that represents the total number of elements in a sequence.(Defined by Enumerable.)

System_CAPS_pubmethod LongCount

Overloaded. Returns an Int64 that represents how many elements in a sequence satisfy a condition.(Defined by Enumerable.)

System_CAPS_pubmethod Max

Overloaded. Returns the maximum value in a generic sequence.(Defined by Enumerable.)

System_CAPS_pubmethod Max

Overloaded. Invokes a transform function on each element of a sequence and returns the maximum Decimal value.(Defined by Enumerable.)

System_CAPS_pubmethod Max

Overloaded. Invokes a transform function on each element of a sequence and returns the maximum Double value.(Defined by Enumerable.)

System_CAPS_pubmethod Max

Overloaded. Invokes a transform function on each element of a sequence and returns the maximum Int32 value.(Defined by Enumerable.)

System_CAPS_pubmethod Max

Overloaded. Invokes a transform function on each element of a sequence and returns the maximum Int64 value.(Defined by Enumerable.)

System_CAPS_pubmethod Max

Overloaded. Invokes a transform function on each element of a sequence and returns the maximum nullable Decimal value.(Defined by Enumerable.)

System_CAPS_pubmethod Max

Overloaded. Invokes a transform function on each element of a sequence and returns the maximum nullable Double value.(Defined by Enumerable.)

System_CAPS_pubmethod Max

Overloaded. Invokes a transform function on each element of a sequence and returns the maximum nullable Int32 value.(Defined by Enumerable.)

System_CAPS_pubmethod Max

Overloaded. Invokes a transform function on each element of a sequence and returns the maximum nullable Int64 value.(Defined by Enumerable.)

System_CAPS_pubmethod Max

Overloaded. Invokes a transform function on each element of a sequence and returns the maximum nullable Single value.(Defined by Enumerable.)

System_CAPS_pubmethod Max

Overloaded. Invokes a transform function on each element of a sequence and returns the maximum Single value.(Defined by Enumerable.)

System_CAPS_pubmethod Max

Overloaded. Invokes a transform function on each element of a generic sequence and returns the maximum resulting value.(Defined by Enumerable.)

System_CAPS_pubmethod Min

Overloaded. Returns the minimum value in a generic sequence.(Defined by Enumerable.)

System_CAPS_pubmethod Min

Overloaded. Invokes a transform function on each element of a sequence and returns the minimum Decimal value.(Defined by Enumerable.)

System_CAPS_pubmethod Min

Overloaded. Invokes a transform function on each element of a sequence and returns the minimum Double value.(Defined by Enumerable.)

System_CAPS_pubmethod Min

Overloaded. Invokes a transform function on each element of a sequence and returns the minimum Int32 value.(Defined by Enumerable.)

System_CAPS_pubmethod Min

Overloaded. Invokes a transform function on each element of a sequence and returns the minimum Int64 value.(Defined by Enumerable.)

System_CAPS_pubmethod Min

Overloaded. Invokes a transform function on each element of a sequence and returns the minimum nullable Decimal value.(Defined by Enumerable.)

System_CAPS_pubmethod Min

Overloaded. Invokes a transform function on each element of a sequence and returns the minimum nullable Double value.(Defined by Enumerable.)

System_CAPS_pubmethod Min

Overloaded. Invokes a transform function on each element of a sequence and returns the minimum nullable Int32 value.(Defined by Enumerable.)

System_CAPS_pubmethod Min

Overloaded. Invokes a transform function on each element of a sequence and returns the minimum nullable Int64 value.(Defined by Enumerable.)

System_CAPS_pubmethod Min

Overloaded. Invokes a transform function on each element of a sequence and returns the minimum nullable Single value.(Defined by Enumerable.)

System_CAPS_pubmethod Min

Overloaded. Invokes a transform function on each element of a sequence and returns the minimum Single value.(Defined by Enumerable.)

System_CAPS_pubmethod Min

Overloaded. Invokes a transform function on each element of a generic sequence and returns the minimum resulting value.(Defined by Enumerable.)

System_CAPS_pubmethod OfType

Filters the elements of an IEnumerable based on a specified type.(Defined by Enumerable.)

System_CAPS_pubmethod OrderBy

Overloaded. Sorts the elements of a sequence in ascending order according to a key.(Defined by Enumerable.)

System_CAPS_pubmethod OrderBy

Overloaded. Sorts the elements of a sequence in ascending order by using a specified comparer.(Defined by Enumerable.)

System_CAPS_pubmethod OrderByDescending

Overloaded. Sorts the elements of a sequence in descending order according to a key.(Defined by Enumerable.)

System_CAPS_pubmethod OrderByDescending

Overloaded. Sorts the elements of a sequence in descending order by using a specified comparer.(Defined by Enumerable.)

System_CAPS_pubmethod Prepend

Adds a value to the beginning of the sequence.(Defined by Enumerable.)

System_CAPS_pubmethod Reverse

Inverts the order of the elements in a sequence.(Defined by Enumerable.)

System_CAPS_pubmethod Select

Overloaded. Projects each element of a sequence into a new form.(Defined by Enumerable.)

System_CAPS_pubmethod Select

Overloaded. Projects each element of a sequence into a new form by incorporating the element's index.(Defined by Enumerable.)

System_CAPS_pubmethod SelectMany

Overloaded. Projects each element of a sequence to an IEnumerable and flattens the resulting sequences into one sequence.(Defined by Enumerable.)

System_CAPS_pubmethod SelectMany

Overloaded. Projects each element of a sequence to an IEnumerable, and flattens the resulting sequences into one sequence. The index of each source element is used in the projected form of that element.(Defined by Enumerable.)

System_CAPS_pubmethod SelectMany

Overloaded. Projects each element of a sequence to an IEnumerable, flattens the resulting sequences into one sequence, and invokes a result selector function on each element therein.(Defined by Enumerable.)

System_CAPS_pubmethod SelectMany

Overloaded. Projects each element of a sequence to an IEnumerable, flattens the resulting sequences into one sequence, and invokes a result selector function on each element therein. The index of each source element is used in the intermediate projected form of that element.(Defined by Enumerable.)

System_CAPS_pubmethod SequenceEqual

Overloaded. Determines whether two sequences are equal by comparing the elements by using the default equality comparer for their type.(Defined by Enumerable.)

System_CAPS_pubmethod SequenceEqual

Overloaded. Determines whether two sequences are equal by comparing their elements by using a specified IEqualityComparer.(Defined by Enumerable.)

System_CAPS_pubmethod Single

Overloaded. Returns the only element of a sequence, and throws an exception if there is not exactly one element in the sequence.(Defined by Enumerable.)

System_CAPS_pubmethod Single

Overloaded. Returns the only element of a sequence that satisfies a specified condition, and throws an exception if more than one such element exists.(Defined by Enumerable.)

System_CAPS_pubmethod SingleOrDefault

Overloaded. Returns the only element of a sequence, or a default value if the sequence is empty; this method throws an exception if there is more than one element in the sequence.(Defined by Enumerable.)

System_CAPS_pubmethod SingleOrDefault

Overloaded. Returns the only element of a sequence that satisfies a specified condition or a default value if no such element exists; this method throws an exception if more than one element satisfies the condition.(Defined by Enumerable.)

System_CAPS_pubmethod Skip

Bypasses a specified number of elements in a sequence and then returns the remaining elements.(Defined by Enumerable.)

System_CAPS_pubmethod SkipWhile

Overloaded. Bypasses elements in a sequence as long as a specified condition is true and then returns the remaining elements.(Defined by Enumerable.)

System_CAPS_pubmethod SkipWhile

Overloaded. Bypasses elements in a sequence as long as a specified condition is true and then returns the remaining elements. The element's index is used in the logic of the predicate function.(Defined by Enumerable.)

System_CAPS_pubmethod Sum

Overloaded. Computes the sum of the sequence of Decimal values that are obtained by invoking a transform function on each element of the input sequence.(Defined by Enumerable.)

System_CAPS_pubmethod Sum

Overloaded. Computes the sum of the sequence of Double values that are obtained by invoking a transform function on each element of the input sequence.(Defined by Enumerable.)

System_CAPS_pubmethod Sum

Overloaded. Computes the sum of the sequence of Int32 values that are obtained by invoking a transform function on each element of the input sequence.(Defined by Enumerable.)

System_CAPS_pubmethod Sum

Overloaded. Computes the sum of the sequence of Int64 values that are obtained by invoking a transform function on each element of the input sequence.(Defined by Enumerable.)

System_CAPS_pubmethod Sum

Overloaded. Computes the sum of the sequence of nullable Decimal values that are obtained by invoking a transform function on each element of the input sequence.(Defined by Enumerable.)

System_CAPS_pubmethod Sum

Overloaded. Computes the sum of the sequence of nullable Double values that are obtained by invoking a transform function on each element of the input sequence.(Defined by Enumerable.)

System_CAPS_pubmethod Sum

Overloaded. Computes the sum of the sequence of nullable Int32 values that are obtained by invoking a transform function on each element of the input sequence.(Defined by Enumerable.)

System_CAPS_pubmethod Sum

Overloaded. Computes the sum of the sequence of nullable Int64 values that are obtained by invoking a transform function on each element of the input sequence.(Defined by Enumerable.)

System_CAPS_pubmethod Sum

Overloaded. Computes the sum of the sequence of nullable Single values that are obtained by invoking a transform function on each element of the input sequence.(Defined by Enumerable.)

System_CAPS_pubmethod Sum

Overloaded. Computes the sum of the sequence of Single values that are obtained by invoking a transform function on each element of the input sequence.(Defined by Enumerable.)

System_CAPS_pubmethod Take

Returns a specified number of contiguous elements from the start of a sequence.(Defined by Enumerable.)

System_CAPS_pubmethod TakeWhile

Overloaded. Returns elements from a sequence as long as a specified condition is true.(Defined by Enumerable.)

System_CAPS_pubmethod TakeWhile

Overloaded. Returns elements from a sequence as long as a specified condition is true. The element's index is used in the logic of the predicate function.(Defined by Enumerable.)

System_CAPS_pubmethod ToArray

Creates an array from a IEnumerable.(Defined by Enumerable.)

System_CAPS_pubmethod ToDictionary

Overloaded. Creates a Dictionary from an IEnumerable according to a specified key selector function.(Defined by Enumerable.)

System_CAPS_pubmethod ToDictionary

Overloaded. Creates a Dictionary from an IEnumerable according to a specified key selector function and key comparer.(Defined by Enumerable.)

System_CAPS_pubmethod ToDictionary

Overloaded. Creates a Dictionary from an IEnumerable according to specified key selector and element selector functions.(Defined by Enumerable.)

System_CAPS_pubmethod ToDictionary

Overloaded. Creates a Dictionary from an IEnumerable according to a specified key selector function, a comparer, and an element selector function.(Defined by Enumerable.)

System_CAPS_pubmethod ToList

Creates a List from an IEnumerable.(Defined by Enumerable.)

System_CAPS_pubmethod ToLookup

Overloaded. Creates a Lookup from an IEnumerable according to a specified key selector function.(Defined by Enumerable.)

System_CAPS_pubmethod ToLookup

Overloaded. Creates a Lookup from an IEnumerable according to a specified key selector function and key comparer.(Defined by Enumerable.)

System_CAPS_pubmethod ToLookup

Overloaded. Creates a Lookup from an IEnumerable according to specified key selector and element selector functions.(Defined by Enumerable.)

System_CAPS_pubmethod ToLookup

Overloaded. Creates a Lookup from an IEnumerable according to a specified key selector function, a comparer and an element selector function.(Defined by Enumerable.)

System_CAPS_pubmethod Union

Overloaded. Produces the set union of two sequences by using the default equality comparer.(Defined by Enumerable.)

System_CAPS_pubmethod Union

Overloaded. Produces the set union of two sequences by using a specified IEqualityComparer.(Defined by Enumerable.)

System_CAPS_pubmethod Where

Overloaded. Filters a sequence of values based on a predicate.(Defined by Enumerable.)

System_CAPS_pubmethod Where

Overloaded. Filters a sequence of values based on a predicate. Each element's index is used in the logic of the predicate function.(Defined by Enumerable.)

System_CAPS_pubmethod Zip

Applies a specified function to the corresponding elements of two sequences, producing a sequence of the results.(Defined by Enumerable.)

An instance of the ReadOnlyCollection generic class is always read-only. A collection that is read-only is simply a collection with a wrapper that prevents modifying the collection; therefore, if changes are made to the underlying collection, the read-only collection reflects those changes. See Collection for a modifiable version of this class.

Notes to Implementers:

This base class is provided to make it easier for implementers to create a generic read-only custom collection. Implementers are encouraged to extend this base class instead of creating their own.

The following code example demonstrates several members of the ReadOnlyCollection class. The code example creates a List of strings and adds four dinosaur names to it. The code example then wraps the list in a ReadOnlyCollection.

After demonstrating the , Contains, , and IListIndexOf members, the code example shows that the ReadOnlyCollection is just a wrapper for the original List by adding a new item to the List and displaying the contents of the ReadOnlyCollection.

Finally, the code example creates an array larger than the collection and uses the CopyTo method to insert the elements of the collection into the middle of the array.

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

public class Example
{
    public static void Main()
    {
        List<string> dinosaurs = new List<string>();

        dinosaurs.Add("Tyrannosaurus");
        dinosaurs.Add("Amargasaurus");
        dinosaurs.Add("Deinonychus");
        dinosaurs.Add("Compsognathus");

        ReadOnlyCollection<string> readOnlyDinosaurs = 
            new ReadOnlyCollection<string>(dinosaurs);

        Console.WriteLine();
        foreach( string dinosaur in readOnlyDinosaurs )
        {
            Console.WriteLine(dinosaur);
        }

        Console.WriteLine("\nCount: {0}", readOnlyDinosaurs.Count);

        Console.WriteLine("\nContains(\"Deinonychus\"): {0}", 
            readOnlyDinosaurs.Contains("Deinonychus"));

        Console.WriteLine("\nreadOnlyDinosaurs[3]: {0}", 
            readOnlyDinosaurs[3]);

        Console.WriteLine("\nIndexOf(\"Compsognathus\"): {0}", 
            readOnlyDinosaurs.IndexOf("Compsognathus"));

        Console.WriteLine("\nInsert into the wrapped List:");
        Console.WriteLine("Insert(2, \"Oviraptor\")");
        dinosaurs.Insert(2, "Oviraptor");

        Console.WriteLine();
        foreach( string dinosaur in readOnlyDinosaurs )
        {
            Console.WriteLine(dinosaur);
        }

        string[] dinoArray = new string[readOnlyDinosaurs.Count + 2];
        readOnlyDinosaurs.CopyTo(dinoArray, 1);

        Console.WriteLine("\nCopied array has {0} elements:", 
            dinoArray.Length);
        foreach( string dinosaur in dinoArray )
        {
            Console.WriteLine("\"{0}\"", dinosaur);
        }
    }
}

/* This code example produces the following output:

Tyrannosaurus
Amargasaurus
Deinonychus
Compsognathus

Count: 4

Contains("Deinonychus"): True

readOnlyDinosaurs[3]: Compsognathus

IndexOf("Compsognathus"): 3

Insert into the wrapped List:
Insert(2, "Oviraptor")

Tyrannosaurus
Amargasaurus
Oviraptor
Deinonychus
Compsognathus

Copied array has 7 elements:
""
"Tyrannosaurus"
"Amargasaurus"
"Oviraptor"
"Deinonychus"
"Compsognathus"
""
 */
Imports System
Imports System.Collections.Generic
Imports System.Collections.ObjectModel

Public Class Example

    Public Shared Sub Main()

        Dim dinosaurs As New List(Of String)

        dinosaurs.Add("Tyrannosaurus")
        dinosaurs.Add("Amargasaurus")
        dinosaurs.Add("Deinonychus")
        dinosaurs.Add("Compsognathus")

        Dim readOnlyDinosaurs As _
            New ReadOnlyCollection(Of String)(dinosaurs)

        Console.WriteLine()
        For Each dinosaur As String In readOnlyDinosaurs
            Console.WriteLine(dinosaur)
        Next

        Console.WriteLine(vbLf & "Count: {0}", _
            readOnlyDinosaurs.Count)

        Console.WriteLine(vbLf & "Contains(""Deinonychus""): {0}", _
            readOnlyDinosaurs.Contains("Deinonychus"))

        Console.WriteLine(vbLf & _
            "readOnlyDinosaurs(3): {0}", readOnlyDinosaurs(3))

        Console.WriteLine(vbLf & "IndexOf(""Compsognathus""): {0}", _
            readOnlyDinosaurs.IndexOf("Compsognathus"))

        Console.WriteLine(vbLf & "Insert into the wrapped List:")
        Console.WriteLine("Insert(2, ""Oviraptor"")")
        dinosaurs.Insert(2, "Oviraptor")

        Console.WriteLine()
        For Each dinosaur As String In readOnlyDinosaurs
            Console.WriteLine(dinosaur)
        Next

        Dim dinoArray(readOnlyDinosaurs.Count + 1) As String
        readOnlyDinosaurs.CopyTo(dinoArray, 1)

        Console.WriteLine(vbLf & "Copied array has {0} elements:", _
            dinoArray.Length)
        For Each dinosaur As String In dinoArray
            Console.WriteLine("""{0}""", dinosaur)
        Next

   End Sub
End Class

' This code example produces the following output:
'
'Tyrannosaurus
'Amargasaurus
'Deinonychus
'Compsognathus
'
'Count: 4
'
'Contains("Deinonychus"): True
'
'readOnlyDinosaurs(3): Compsognathus
'
'IndexOf("Compsognathus"): 3
'
'Insert into the wrapped List:
'Insert(2, "Oviraptor")
'
'Tyrannosaurus
'Amargasaurus
'Oviraptor
'Deinonychus
'Compsognathus
'
'Copied array has 7 elements:
'""
'"Tyrannosaurus"
'"Amargasaurus"
'"Oviraptor"
'"Deinonychus"
'"Compsognathus"
'""
using namespace System;
using namespace System::Collections::Generic;
using namespace System::Collections::ObjectModel;

void main()
{
    List<String^>^ dinosaurs = gcnew List<String^>();

    dinosaurs->Add("Tyrannosaurus");
    dinosaurs->Add("Amargasaurus");
    dinosaurs->Add("Deinonychus");
    dinosaurs->Add("Compsognathus");

    ReadOnlyCollection<String^>^ readOnlyDinosaurs = 
        gcnew ReadOnlyCollection<String^>(dinosaurs);

    Console::WriteLine();
    for each(String^ dinosaur in readOnlyDinosaurs )
    {
        Console::WriteLine(dinosaur);
    }

    Console::WriteLine("\nCount: {0}", readOnlyDinosaurs->Count);

    Console::WriteLine("\nContains(\"Deinonychus\"): {0}", 
        readOnlyDinosaurs->Contains("Deinonychus"));

    Console::WriteLine("\nreadOnlyDinosaurs[3]: {0}", 
        readOnlyDinosaurs[3]);

    Console::WriteLine("\nIndexOf(\"Compsognathus\"): {0}", 
        readOnlyDinosaurs->IndexOf("Compsognathus"));

    Console::WriteLine("\nInsert into the wrapped List:");
    Console::WriteLine("Insert(2, \"Oviraptor\")");
    dinosaurs->Insert(2, "Oviraptor");

    Console::WriteLine();
    for each( String^ dinosaur in readOnlyDinosaurs )
    {
        Console::WriteLine(dinosaur);
    }

    array<String^>^ dinoArray = 
        gcnew array<String^>(readOnlyDinosaurs->Count + 2);
    readOnlyDinosaurs->CopyTo(dinoArray, 1);

    Console::WriteLine("\nCopied array has {0} elements:", 
        dinoArray->Length);
    for each( String^ dinosaur in dinoArray )
    {
        Console::WriteLine("\"{0}\"", dinosaur);
    }
}

/* This code example produces the following output:

Tyrannosaurus
Amargasaurus
Deinonychus
Compsognathus

Count: 4

Contains("Deinonychus"): True

readOnlyDinosaurs[3]: Compsognathus

IndexOf("Compsognathus"): 3

Insert into the wrapped List:
Insert(2, "Oviraptor")

Tyrannosaurus
Amargasaurus
Oviraptor
Deinonychus
Compsognathus

Copied array has 7 elements:
""
"Tyrannosaurus"
"Amargasaurus"
"Oviraptor"
"Deinonychus"
"Compsognathus"
""
 */
Universal Windows Platform
Available since 8
.NET Framework
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1

Public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

A ReadOnlyCollection can support multiple readers concurrently, as long as the collection is not modified. Even so, enumerating through a collection is intrinsically not a thread-safe procedure. To guarantee thread safety during enumeration, you can lock the collection during the entire enumeration. To allow the collection to be accessed by multiple threads for reading and writing, you must implement your own synchronization.

Return to top