Ler en inglés Editar

Compartir por


CollectionExtensions.AsReadOnly Method

Definition

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Overloads

AsReadOnly<T>(IList<T>)

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

AsReadOnly<T>(ISet<T>)
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.

C#
public static System.Collections.ObjectModel.ReadOnlyCollection<T> AsReadOnly<T>(this System.Collections.Generic.IList<T> list);

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

.NET 10 e outras versións
Produto Versións
.NET 7, 8, 9, 10

AsReadOnly<T>(ISet<T>)

C#
public static System.Collections.ObjectModel.ReadOnlySet<T> AsReadOnly<T>(this System.Collections.Generic.ISet<T> set);

Type Parameters

T

Parameters

set
ISet<T>

Returns

Applies to

.NET 10
Produto Versións
.NET 10

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.

C#
public static System.Collections.ObjectModel.ReadOnlyDictionary<TKey,TValue> AsReadOnly<TKey,TValue>(this System.Collections.Generic.IDictionary<TKey,TValue> dictionary);

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

.NET 10 e outras versións
Produto Versións
.NET 7, 8, 9, 10