SortedList<TKey,TValue>.Values Proprietà

Definizione

Ottiene una raccolta contenente i valori di 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)

Valore della proprietà

IList<TValue>

Raccolta IList<T> contenente i valori di SortedList<TKey,TValue>.

Esempio

In questo esempio di codice viene illustrato come enumerare i valori nell'elenco ordinato usando la Values proprietà e come enumerare le chiavi e i valori nell'elenco ordinato.

L'esempio mostra anche come usare la Values proprietà per il recupero indicizzato efficiente dei valori.

Questo esempio di codice fa parte di un esempio più ampio fornito per la SortedList<TKey,TValue> classe .

// 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}"

Commenti

L'ordine dei valori in IList<T> è uguale all'ordine in SortedList<TKey,TValue>.

L'oggetto restituito IList<T> non è una copia statica, ma IList<T> fa riferimento ai valori nell'oggetto originale SortedList<TKey,TValue>. Di conseguenza, le modifiche apportate all'oggetto SortedList<TKey,TValue> continuano a essere riflesse in IList<T>.

L'insieme Values restituito dalla proprietà fornisce un modo efficiente per recuperare i valori in base all'indice. Non è necessario rigenerare l'elenco quando si accede alla proprietà, perché l'elenco è solo un wrapper per la matrice interna di valori. Il codice seguente illustra l'uso della proprietà per il Values recupero indicizzato di valori da un elenco ordinato di stringhe:

String^ v = mySortedList->Values[3];
string v = mySortedList.Values[3];
Dim v As String = mySortedList.Values(3)
let v = mySortedList.Values[3]

Il recupero del valore di questa proprietà è un'operazione O(1).

Si applica a

Vedi anche