SortedList<TKey,TValue>.Values Właściwość
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Pobiera kolekcję zawierającą wartości w obiekcie SortedList<TKey,TValue>.
public:
property System::Collections::Generic::IList<TValue> ^ Values { System::Collections::Generic::IList<TValue> ^ get(); };
public System.Collections.Generic.IList<TValue> Values { get; }
member this.Values : System.Collections.Generic.IList<'Value>
Public ReadOnly Property Values As IList(Of TValue)
Wartość właściwości
- IList<TValue>
Element IList<T> zawierający wartości w obiekcie SortedList<TKey,TValue>.
Przykłady
W tym przykładzie kodu pokazano, jak wyliczać wartości na posortowanej liście przy użyciu Values właściwości oraz jak wyliczać klucze i wartości na posortowanej liście.
W przykładzie pokazano również, jak używać Values właściwości do wydajnego indeksowania pobierania wartości.
Ten przykład kodu jest częścią większego przykładu udostępnionego SortedList<TKey,TValue> dla klasy .
// To get the values alone, use the Values property.
IList<String^>^ ilistValues = openWith->Values;
// The elements of the list are strongly typed with the
// type that was specified for the SortedList values.
Console::WriteLine();
for each( String^ s in ilistValues )
{
Console::WriteLine("Value = {0}", s);
}
// The Values property is an efficient way to retrieve
// values by index.
Console::WriteLine("\nIndexed retrieval using the Values " +
"property: Values[2] = {0}", openWith->Values[2]);
// To get the values alone, use the Values property.
IList<string> ilistValues = openWith.Values;
// The elements of the list are strongly typed with the
// type that was specified for the SortedList values.
Console.WriteLine();
foreach( string s in ilistValues )
{
Console.WriteLine("Value = {0}", s);
}
// The Values property is an efficient way to retrieve
// values by index.
Console.WriteLine("\nIndexed retrieval using the Values " +
"property: Values[2] = {0}", openWith.Values[2]);
' To get the values alone, use the Values property.
Dim ilistValues As IList(Of String) = openWith.Values
' The elements of the list are strongly typed with the
' type that was specified for the SortedList values.
Console.WriteLine()
For Each s As String In ilistValues
Console.WriteLine("Value = {0}", s)
Next s
' The Values property is an efficient way to retrieve
' values by index.
Console.WriteLine(vbLf & "Indexed retrieval using the " & _
"Values property: Values(2) = {0}", openWith.Values(2))
// When you use foreach to enumerate list elements,
// the elements are retrieved as KeyValuePair objects.
Console::WriteLine();
for each( KeyValuePair<String^, String^> kvp in openWith )
{
Console::WriteLine("Key = {0}, Value = {1}",
kvp.Key, kvp.Value);
}
// When you use foreach to enumerate list 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 list 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
Uwagi
Kolejność wartości w obiekcie IList<T> jest taka sama jak kolejność w obiekcie SortedList<TKey,TValue>.
Zwrócona IList<T> wartość nie jest kopią statyczną. IList<T> Zamiast tego element odwołuje się do wartości w oryginalnym obiekcie SortedList<TKey,TValue>. W związku z SortedList<TKey,TValue> tym zmiany w obiekcie nadal będą odzwierciedlane w pliku IList<T>.
Kolekcja zwracana przez Values właściwość zapewnia wydajny sposób pobierania wartości według indeksu. Ponowne generowanie listy podczas uzyskiwania dostępu do właściwości nie jest konieczne, ponieważ lista jest tylko otoką dla wewnętrznej tablicy wartości. Poniższy kod przedstawia użycie Values właściwości do indeksowanego pobierania wartości z posortowanej listy ciągów:
String^ v = mySortedList->Values[3];
string v = mySortedList.Values[3];
Dim v As String = mySortedList.Values(3)
Pobieranie wartości tej właściwości jest operacją O(1).