Visual C++: Vérification de l’existance de Pair Valeur/clé dans Hashtable

Author:


Download


#include "stdafx.h"

using namespace System;
using namespace System::Collections;
/*
  Exemple de Tableau Associatif.
  MesExemples.com
*/

Int32 main(void)
{
	try
	{
		// Créer un objet Hashtable
		Hashtable ^hash  = gcnew Hashtable();
		
		 // Créer tableaux de clé et valeurs
		 array ^keys = gcnew array{ "fr", "en", "gr", "de" }; // Représentent les codes de pays
         array ^values = gcnew array{ "français", "anglais", "grec", "allemand" };// Représentent les pays

		 // Combiner les deux tableaux dans un tableau associatif HashTable
		     for (Int32 i = 0; i Length; i++)
		   {
				hash->Add(keys[i], values[i]);
			}


          // Vérifier si la clé "fr" existe dans le hashTable
			 Console::Write("Fr existe-il? {0}\n Allemand existe-il?{1}", hash->Contains("fr")
				 , hash->Contains("allemand"));
		


		
  
	}  catch (Exception ^e)
    {
        Console::WriteLine(e->StackTrace);
    }
    Console::ReadLine();
    return 0;
}



Leave a Reply

Your email address will not be published. Required fields are marked *