Cet article a fait l'objet d'une traduction manuelle. Déplacez votre pointeur sur les phrases de l'article pour voir la version originale de ce texte. |
Traduction
Source
|
Type.Equals, méthode (Type)
.NET Framework 4
Espace de noms :
System
Assembly : mscorlib (dans mscorlib.dll)
Paramètres
- o
- Type : System.Type
Objet dont le type de système sous-jacent doit être comparé au type de système sous-jacent du Type actuel.
Valeur de retour
Type : System.Booleantrue si le type de système sous-jacent de o est identique au type de système sous-jacent du Type en cours ; sinon, false.
Implémentations
_Type.Equals(Type)L'exemple suivant utilise Equals pour comparer deux types.
using System; using System.Reflection; class Example { public static void Main() { Type a = typeof(System.String); Type b = typeof(System.Int32); Console.WriteLine("{0} == {1}: {2}", a, b, a.Equals(b)); // The Type objects in a and b are not equal, // because they represent different types. a = typeof(Example); b = new Example().GetType(); Console.WriteLine("{0} is equal to {1}: {2}", a, b, a.Equals(b)); // The Type objects in a and b are equal, // because they both represent type Example. b = typeof(Type); Console.WriteLine("typeof({0}).Equals(typeof({1})): {2}", a, b, a.Equals(b)); // The Type objects in a and b are not equal, // because variable a represents type Example // and variable b represents type Type. //Console.ReadLine(); } } // /* This code example produces the following output: System.String == System.Int32: False Example is equal to Example: True typeof(Example).Equals(typeof(System.Type)): False */
Windows 7, Windows Vista SP1 ou ultérieur, Windows XP SP3, Windows XP SP2 Édition x64, Windows Server 2008 (installation minimale non prise en charge), Windows Server 2008 R2 (installation minimale prise en charge avec SP1 ou version ultérieure), Windows Server 2003 SP2
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.