Array.AsReadOnly<'T> Method ('T[])


Returns a read-only wrapper for the specified array.

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

static member AsReadOnly<'T> : 
        array:'T[] -> ReadOnlyCollection<'T>


Type: 'T[]

The one-dimensional, zero-based array to wrap in a read-only ReadOnlyCollection<'T> wrapper.

Return Value

Type: System.Collections.ObjectModel.ReadOnlyCollection<'T>

A read-only ReadOnlyCollection<'T> wrapper for the specified array.

Type Parameters


The type of the elements of the array.

Exception Condition

array is null.

To prevent any modifications to the array, expose the array only through this wrapper.

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.

This method is an O(1) operation.

The following example wraps an array in a read-only ReadOnlyCollection<'T>.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 2.0
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top