Export (0) Print
Expand All

Array.AsReadOnly(T) Method

Returns a read-only wrapper for the specified array.

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

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

Type Parameters

T

The type of the elements of the array.

Parameters

array
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.

ExceptionCondition
ArgumentNullException

array is a null reference (Nothing in Visual Basic).

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

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft