SortedList<TKey,TValue>.Values 屬性

定義

取得集合,包含 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)

屬性值

IList<TValue>

IList<T>,包含 SortedList<TKey,TValue> 中的值。

範例

此程式代碼範例示範如何使用 屬性列舉排序列表中的 Values 值,以及如何列舉排序列表中的索引鍵和值。

此範例也會示範如何使用 Values 屬性,以有效率地擷取索引值。

此程式代碼範例是針對 類別提供的較大範例的 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();
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}"

備註

中的 IList<T> 值順序與 中 SortedList<TKey,TValue>的順序相同。

IList<T> 回的 不是靜態複本, IList<T> 而是參考原始 SortedList<TKey,TValue>中的值。 因此,對的變更 SortedList<TKey,TValue> 會繼續反映在 中 IList<T>

屬性傳回的 Values 集合提供有效率的方式,以依索引擷取值。 存取屬性時不需要重新產生清單,因為清單只是值內部數位的包裝函式。 下列程式代碼顯示從已排序字串清單中擷取值的索引擷 Values 取屬性:

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

擷取這個屬性的值是一種 O(1) 運算。

適用於

另請參閱