SortedList<TKey,TValue>.Values Właściwość

Definicja

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 pobierania indeksowanych wartości.

Ten przykład kodu jest częścią większego przykładu podanego 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))
// To get the values alone, use the Values property.
let ilistValues = openWith.Values;

// The elements of the list are strongly typed with the
// type that was specified for the SortedList values.
Console.WriteLine()
for s in ilistValues do
    printfn $"Value = {s}"

// The Values property is an efficient way to retrieve
// values by index.
printf "\nIndexed retrieval using the Values "
printfn $"property: Values[2] = {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
// When you use foreach to enumerate list elements,
// the elements are retrieved as KeyValuePair objects.
Console.WriteLine()
for kvp in openWith do
    printfn $"Key = {kvp.Key}, Value = {kvp.Value}"

Uwagi

Kolejność wartości w elemecie IList<T> jest taka sama jak kolejność w elemecie SortedList<TKey,TValue>.

Zwrócona IList<T> kopia nie jest kopią statyczną. Zamiast tego IList<T> element odwołuje się do wartości w oryginalnym SortedList<TKey,TValue>obiekcie . W związku z tym zmiany w SortedList<TKey,TValue> dalszym ciągu zostaną odzwierciedlone w obiekcie IList<T>.

Kolekcja zwrócona przez Values właściwość zapewnia wydajny sposób pobierania wartości według indeksu. Nie jest konieczne ponowne wygenerowanie listy po korzystaniu z właściwości, ponieważ lista jest tylko otoką dla wewnętrznej tablicy wartości. Poniższy kod przedstawia użycie Values właściwości indeksowanej 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)
let v = mySortedList.Values[3]

Pobieranie wartości tej właściwości jest operacją O(1).

Dotyczy

Zobacz też