SortedDictionary<TKey,TValue>.Values Свойство
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Возвращает коллекцию, содержащую значения из словаря SortedDictionary<TKey,TValue>.
public:
property System::Collections::Generic::SortedDictionary<TKey, TValue>::ValueCollection ^ Values { System::Collections::Generic::SortedDictionary<TKey, TValue>::ValueCollection ^ get(); };
public System.Collections.Generic.SortedDictionary<TKey,TValue>.ValueCollection Values { get; }
member this.Values : System.Collections.Generic.SortedDictionary<'Key, 'Value>.ValueCollection
Public ReadOnly Property Values As SortedDictionary(Of TKey, TValue).ValueCollection
Коллекция SortedDictionary<TKey,TValue>.ValueCollection, содержащая значения из словаря SortedDictionary<TKey,TValue>.
В этом примере кода показано, как перечислить значения в словаре с помощью Values свойства и как перечислить ключи и значения в словаре.
Этот пример входит в состав более крупного примера использования класса SortedDictionary<TKey,TValue>.
// To get the values alone, use the Values property.
SortedDictionary<string, string>.ValueCollection valueColl =
openWith.Values;
// The elements of the ValueCollection are strongly typed
// with the type that was specified for dictionary values.
Console.WriteLine();
foreach( string s in valueColl )
{
Console.WriteLine("Value = {0}", s);
}
' To get the values alone, use the Values property.
Dim valueColl _
As SortedDictionary(Of String, String).ValueCollection = _
openWith.Values
' The elements of the ValueCollection are strongly typed
' with the type that was specified for dictionary values.
Console.WriteLine()
For Each s As String In valueColl
Console.WriteLine("Value = {0}", s)
Next s
// When you use foreach to enumerate dictionary elements,
// the elements are retrieved as KeyValuePair objects.
Console.WriteLine();
foreach( KeyValuePair<string, string> kvp in openWith )
{
Console.WriteLine("Key = {0}, Value = {1}",
kvp.Key, kvp.Value);
}
' When you use foreach to enumerate dictionary elements,
' the elements are retrieved as KeyValuePair objects.
Console.WriteLine()
For Each kvp As KeyValuePair(Of String, String) In openWith
Console.WriteLine("Key = {0}, Value = {1}", _
kvp.Key, kvp.Value)
Next kvp
Значения в SortedDictionary<TKey,TValue>.ValueCollection сортируются по свойству Comparer и находятся в том же порядке, что и связанные ключи в объекте SortedDictionary<TKey,TValue>.KeyCollection , возвращаемом свойством Keys .
Возвращаемый SortedDictionary<TKey,TValue>.ValueCollection объект не является статической копией; SortedDictionary<TKey,TValue>.ValueCollection вместо этого ссылается обратно на значения в исходном SortedDictionary<TKey,TValue>объекте . Поэтому изменения в по-прежнему SortedDictionary<TKey,TValue> отражаются в SortedDictionary<TKey,TValue>.ValueCollection.
Получение значения этого свойства является операцией O(1).
Продукт | Версии |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
Отзыв о .NET
.NET — это проект с открытым исходным кодом. Выберите ссылку, чтобы оставить отзыв: