|
Cet article a fait l'objet d'une traduction automatique. Déplacez votre pointeur sur les phrases de l'article pour voir la version originale de ce texte. Informations supplémentaires.
|
Traduction
Source
|
Dictionary<TKey, TValue>.IDictionary.Contains, méthode
Espace de noms : System.Collections.Generic
Assembly : mscorlib (dans mscorlib.dll)
Paramètres
- key
- Type : System.Object
Clé à rechercher dans IDictionary.
Valeur de retour
Type : System.BooleanImplémentations
IDictionary.Contains(Object)| Exception | Condition |
|---|---|
| ArgumentNullException |
using System; using System.Collections; using System.Collections.Generic; public class Example { public static void Main() { // Create a new dictionary of strings, with string keys, // and access it using the IDictionary interface. // IDictionary openWith = new Dictionary<string, string>(); // Add some elements to the dictionary. There are no // duplicate keys, but some of the values are duplicates. // IDictionary.Add throws an exception if incorrect types // are supplied for key or value. openWith.Add("txt", "notepad.exe"); openWith.Add("bmp", "paint.exe"); openWith.Add("dib", "paint.exe"); openWith.Add("rtf", "wordpad.exe"); ... // Contains can be used to test keys before inserting // them. if (!openWith.Contains("ht")) { openWith.Add("ht", "hypertrm.exe"); Console.WriteLine("Value added for key = \"ht\": {0}", openWith["ht"]); } // IDictionary.Contains returns false if the wrong data // type is supplied. Console.WriteLine("openWith.Contains(29.7) returns {0}", openWith.Contains(29.7)); ... } }
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (rôle principal du serveur non pris en charge), Windows Server 2008 R2 (rôle principal du serveur pris en charge avec SP1 ou version ultérieure ; Itanium non pris en charge)
Le .NET Framework ne prend pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.