SortedList<TKey,TValue>.Values 属性

定义

获取包含 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.

适用于

另请参阅