SortedList<TKey,TValue>.Values SortedList<TKey,TValue>.Values SortedList<TKey,TValue>.Values SortedList<TKey,TValue>.Values Property

定義

取得集合,包含 SortedList<TKey,TValue> 中的值。Gets a collection containing the values in the 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> 中的值。A IList<T> containing the values in the SortedList<TKey,TValue>.

範例

這個程式碼範例示範如何使用Values屬性列舉已排序清單中的值,以及如何列舉已排序清單中的索引鍵和值。This code example shows how to enumerate the values in the sorted list using the Values property, and how to enumerate the keys and values in the sorted list.

此範例也會示範如何使用Values屬性,以有效率地取得值的索引抓取。The example also shows how to use the Values property for efficient indexed retrieval of values.

這個程式碼範例是針對SortedList<TKey,TValue>類別提供之較大範例的一部分。This code example is part of a larger example provided for the SortedList<TKey,TValue> class.

// 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 SorteList 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 SorteList 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

備註

IList<T>的值順序與SortedList<TKey,TValue>中的順序相同。The order of the values in the IList<T> is the same as the order in the SortedList<TKey,TValue>.

傳回IList<T>的不是靜態複本IList<T> ,而是指回原始SortedList<TKey,TValue>中的值。The returned IList<T> is not a static copy; instead, the IList<T> refers back to the values in the original SortedList<TKey,TValue>. 因此,的SortedList<TKey,TValue>變更會繼續反映IList<T>在中。Therefore, changes to the SortedList<TKey,TValue> continue to be reflected in the IList<T>.

Values屬性所傳回的集合會提供有效率的方式,依索引來抓取值。The collection returned by the Values property provides an efficient way to retrieve values by index. 當存取屬性時,不需要重新產生清單,因為清單只是值內部陣列的包裝函式。It is not necessary to regenerate the list when the property is accessed, because the list is just a wrapper for the internal array of values. 下列程式碼示範如何使用Values屬性,從已排序的字串清單中取得值的索引抓取:The following code shows the use of the Values property for indexed retrieval of values from a sorted list of strings:

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

擷取這個屬性的值是一種 O(1) 運算。Retrieving the value of this property is an O(1) operation.

適用於

另請參閱