SortedList<TKey,TValue>.Values Vlastnost
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Získá kolekci obsahující hodnoty v objektu 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)
Hodnota vlastnosti
A IList<T> obsahující hodnoty v objektu SortedList<TKey,TValue>.
Příklady
Tento příklad kódu ukazuje, jak vytvořit výčet hodnot v seřazeného seznamu pomocí Values vlastnosti a jak vytvořit výčet klíčů a hodnot v seřazeného seznamu.
Příklad také ukazuje, jak použít Values vlastnost pro efektivní indexované načítání hodnot.
Tento příklad kódu je součástí většího příkladu uvedeného pro třídu SortedList<TKey,TValue>.
// 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();
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}"
Poznámky
Pořadí hodnot v pořadí IList<T> je stejné jako pořadí v objektu SortedList<TKey,TValue>.
Vrácená IList<T> hodnota není statická kopie. IList<T> Místo toho odkazuje zpět na hodnoty v původním SortedList<TKey,TValue>souboru . Proto se změny nadále SortedList<TKey,TValue> projeví v IList<T>souboru .
Kolekce vrácená Values vlastností poskytuje efektivní způsob, jak načíst hodnoty podle indexu. Při přístupu k vlastnosti není nutné znovu vygenerovat seznam, protože seznam je jen obálka pro interní pole hodnot. Následující kód ukazuje použití Values vlastnosti pro indexované načtení hodnot z seřazeného seznamu řetězců:
string v = mySortedList.Values[3];
Dim v As String = mySortedList.Values(3)
let v = mySortedList.Values[3]
Načtení hodnoty této vlastnosti je operace O(1).