Edit

Share via


CollectionExtensions.AsReadOnly Method

Definition

Overloads

AsReadOnly<T>(IList<T>)

Returns a read-only ReadOnlyCollection<T> wrapper for the specified list.

AsReadOnly<TKey,TValue>(IDictionary<TKey,TValue>)

Returns a read-only ReadOnlyDictionary<TKey,TValue> wrapper for the current dictionary.

AsReadOnly<T>(IList<T>)

Source:
CollectionExtensions.cs
Source:
CollectionExtensions.cs
Source:
CollectionExtensions.cs

Returns a read-only ReadOnlyCollection<T> wrapper for the specified list.

public:
generic <typename T>
[System::Runtime::CompilerServices::Extension]
 static System::Collections::ObjectModel::ReadOnlyCollection<T> ^ AsReadOnly(System::Collections::Generic::IList<T> ^ list);
public static System.Collections.ObjectModel.ReadOnlyCollection<T> AsReadOnly<T> (this System.Collections.Generic.IList<T> list);
static member AsReadOnly : System.Collections.Generic.IList<'T> -> System.Collections.ObjectModel.ReadOnlyCollection<'T>
<Extension()>
Public Function AsReadOnly(Of T) (list As IList(Of T)) As ReadOnlyCollection(Of T)

Type Parameters

T

The type of elements in the collection.

Parameters

list
IList<T>

The list to wrap.

Returns

An object that acts as a read-only wrapper around the current IList<T>.

Exceptions

list is null.

Applies to

AsReadOnly<TKey,TValue>(IDictionary<TKey,TValue>)

Source:
CollectionExtensions.cs
Source:
CollectionExtensions.cs
Source:
CollectionExtensions.cs

Returns a read-only ReadOnlyDictionary<TKey,TValue> wrapper for the current dictionary.

public:
generic <typename TKey, typename TValue>
[System::Runtime::CompilerServices::Extension]
 static System::Collections::ObjectModel::ReadOnlyDictionary<TKey, TValue> ^ AsReadOnly(System::Collections::Generic::IDictionary<TKey, TValue> ^ dictionary);
public static System.Collections.ObjectModel.ReadOnlyDictionary<TKey,TValue> AsReadOnly<TKey,TValue> (this System.Collections.Generic.IDictionary<TKey,TValue> dictionary);
static member AsReadOnly : System.Collections.Generic.IDictionary<'Key, 'Value> -> System.Collections.ObjectModel.ReadOnlyDictionary<'Key, 'Value>
<Extension()>
Public Function AsReadOnly(Of TKey, TValue) (dictionary As IDictionary(Of TKey, TValue)) As ReadOnlyDictionary(Of TKey, TValue)

Type Parameters

TKey

The type of keys in the dictionary.

TValue

The type of values in the dictionary.

Parameters

dictionary
IDictionary<TKey,TValue>

The dictionary to wrap.

Returns

An object that acts as a read-only wrapper around the current IDictionary<TKey,TValue>.

Exceptions

dictionary is null.

Applies to