OrderedDictionary.Values Propriété
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient un objet ICollection contenant les valeurs de la collection 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
Valeur de propriété
Objet ICollection contenant les valeurs de la collection OrderedDictionary.
Implémente
Exemples
L’exemple de code suivant illustre la création et la population d’une OrderedDictionary collection, puis imprime le contenu dans la console. Dans cet exemple, les Keys propriétés et Values sont passées à une méthode qui affiche le contenu. Ce code fait partie d’un exemple de code plus volumineux qui peut être consulté à l’adresse 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
Remarques
L’objet retourné ICollection n’est pas une copie statique ; au lieu de cela, le ICollection renvoie aux valeurs de la collection d’origine OrderedDictionary . Par conséquent, les modifications apportées au OrderedDictionary continuent d’être reflétées dans .ICollection