OrderedDictionary.Values 属性

定义

获取 ICollection 对象,该对象包含 OrderedDictionary 集合中的值。

public:
 property System::Collections::ICollection ^ Values { System::Collections::ICollection ^ get(); };
public System.Collections.ICollection Values { get; }
member this.Values : System.Collections.ICollection
Public ReadOnly Property Values As ICollection

属性值

ICollection

一个 ICollection 对象,它包含 OrderedDictionary 集合中的值。

实现

示例

下面的代码示例演示集合的 OrderedDictionary 创建和填充,然后将内容打印到控制台。 在此示例中,将 Keys 属性 Values 传递给显示内容的方法。 此代码是可在其中查看 OrderedDictionary的大型代码示例的一部分。

// Creates and initializes a OrderedDictionary.
OrderedDictionary^ myOrderedDictionary = gcnew OrderedDictionary();
myOrderedDictionary->Add("testKey1", "testValue1");
myOrderedDictionary->Add("testKey2", "testValue2");
myOrderedDictionary->Add("keyToDelete", "valueToDelete");
myOrderedDictionary->Add("testKey3", "testValue3");

ICollection^ keyCollection = myOrderedDictionary->Keys;
ICollection^ valueCollection = myOrderedDictionary->Values;

// Display the contents using the key and value collections
DisplayContents(keyCollection, valueCollection, myOrderedDictionary->Count);
// Creates and initializes a OrderedDictionary.
OrderedDictionary myOrderedDictionary = new OrderedDictionary();
myOrderedDictionary.Add("testKey1", "testValue1");
myOrderedDictionary.Add("testKey2", "testValue2");
myOrderedDictionary.Add("keyToDelete", "valueToDelete");
myOrderedDictionary.Add("testKey3", "testValue3");

ICollection keyCollection = myOrderedDictionary.Keys;
ICollection valueCollection = myOrderedDictionary.Values;

// Display the contents using the key and value collections
DisplayContents(keyCollection, valueCollection, myOrderedDictionary.Count);
' Creates and initializes a OrderedDictionary.
Dim myOrderedDictionary As New OrderedDictionary()
myOrderedDictionary.Add("testKey1", "testValue1")
myOrderedDictionary.Add("testKey2", "testValue2")
myOrderedDictionary.Add("keyToDelete", "valueToDelete")
myOrderedDictionary.Add("testKey3", "testValue3")

Dim keyCollection As ICollection = myOrderedDictionary.Keys
Dim valueCollection As ICollection = myOrderedDictionary.Values

' Display the contents Imports the key and value collections
DisplayContents( _
    keyCollection, valueCollection, myOrderedDictionary.Count)
// Displays the contents of the OrderedDictionary from its keys and values
static void DisplayContents(
    ICollection^ keyCollection, ICollection^ valueCollection, int dictionarySize)
{
    array<String^>^ myKeys = gcnew array<String^>(dictionarySize);
    array<String^>^ myValues = gcnew array<String^>(dictionarySize);
    keyCollection->CopyTo(myKeys, 0);
    valueCollection->CopyTo(myValues, 0);

    // Displays the contents of the OrderedDictionary
    Console::WriteLine("   INDEX KEY                       VALUE");
    for (int i = 0; i < dictionarySize; i++)
    {
        Console::WriteLine("   {0,-5} {1,-25} {2}",
            i, myKeys[i], myValues[i]);
    }
    Console::WriteLine();
}
// Displays the contents of the OrderedDictionary from its keys and values
public static void DisplayContents(
    ICollection keyCollection, ICollection valueCollection, int dictionarySize)
{
    String[] myKeys = new String[dictionarySize];
    String[] myValues = new String[dictionarySize];
    keyCollection.CopyTo(myKeys, 0);
    valueCollection.CopyTo(myValues, 0);

    // Displays the contents of the OrderedDictionary
    Console.WriteLine("   INDEX KEY                       VALUE");
    for (int i = 0; i < dictionarySize; i++)
    {
        Console.WriteLine("   {0,-5} {1,-25} {2}",
            i, myKeys[i], myValues[i]);
    }
    Console.WriteLine();
}
' Displays the contents of the OrderedDictionary from its keys and values
Public Shared Sub DisplayContents( _
    ByVal keyCollection As ICollection, _
    ByVal valueCollection As ICollection, ByVal dictionarySize As Integer)

    Dim myKeys(dictionarySize) As [String]
    Dim myValues(dictionarySize) As [String]
    keyCollection.CopyTo(myKeys, 0)
    valueCollection.CopyTo(myValues, 0)

    ' Displays the contents of the OrderedDictionary
    Console.WriteLine("   INDEX KEY                       VALUE")
    Dim i As Integer
    For i = 0 To dictionarySize - 1
        Console.WriteLine("   {0,-5} {1,-25} {2}", _
             i, myKeys(i), myValues(i))
    Next i
    Console.WriteLine()
End Sub

注解

返回 ICollection 的对象不是静态副本;而是 ICollection 引用原始 OrderedDictionary 集合中的值。 因此,继续反映对更改的ICollection更改OrderedDictionary

适用于