CollectionExtensions.AsReadOnly 方法

定义

重载

AsReadOnly<T>(IList<T>)

返回指定列表的只读 ReadOnlyCollection<T> 包装器。

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

返回当前字典的只读 ReadOnlyDictionary<TKey,TValue> 包装器。

AsReadOnly<T>(IList<T>)

返回指定列表的只读 ReadOnlyCollection<T> 包装器。

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)

类型参数

T

集合中的元素类型。

参数

list
IList<T>

要包装的列表。

返回

一个对象,作为围绕当前 IList<T> 的只读包装器。

例外

listnull

适用于

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

返回当前字典的只读 ReadOnlyDictionary<TKey,TValue> 包装器。

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)

类型参数

TKey

字典中的键的类型。

TValue

字典中值的类型。

参数

dictionary
IDictionary<TKey,TValue>

要包装的字典。

返回

一个对象,作为围绕当前 IDictionary<TKey,TValue> 的只读包装器。

例外

dictionarynull

适用于