Equals(Type)public: bool Equals(Type ^ o); public: virtual bool Equals(Type ^ o); public bool Equals (Type o); public virtual bool Equals (Type? o); public virtual bool Equals (Type o); override this.Equals : Type -> bool Public Function Equals (o As Type) As Boolean Public Overridable Function Equals (o As Type) As Boolean Boolean true if the underlying system type of o is the same as the underlying system type of the current Type; otherwise, false. ExamplesThe following example uses Equals to compare two 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 */ open System type Example() = class end do let a = typeof<string> let b = typeof<int> printfn $"{a} == {b}: {a.Equals b}" // The Type objects in a and b are not equal, // because they represent different types. let a = typeof<Example> let b = Example().GetType() printfn $"{a} is equal to {b}: {a.Equals b}" // The Type objects in a and b are equal, // because they both represent type Example. let b = typeof<Type> printfn $"typeof({a}).Equals(typeof({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. (* 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 *) Imports System.Reflection Class Example Public Shared Sub Main() Dim a As Type = GetType(System.String) Dim b As Type = GetType(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 = GetType(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 = GetType(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() End Sub End Class ' ' 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 'See alsoApplies to
Equals(Object)public: override bool Equals(System::Object ^ o); public override bool Equals (object o); public override bool Equals (object? o); override this.Equals : obj -> bool Public Overrides Function Equals (o As Object) As Boolean Boolean true if the underlying system type of o is the same as the underlying system type of the current Type; otherwise, false. This method also returns false if:
ExamplesThe following example uses Equals(Object) to compare various Type object instances with various Object instances. Two things are particularly worth noting about the example:
RemarksThis method overrides Object.Equals. It casts o to an object of type Type and calls the Type.Equals(Type) method. See alsoApplies to
public: abstract int Compare(T x, T y); public abstract int Compare (T x, T y); public abstract int Compare (T? x, T? y); abstract member Compare : 'T * 'T -> int Public MustOverride Function Compare (x As T, y As T) As Integer Int32 A signed integer that indicates the relative values of x and y, as shown in the following table.
ExamplesThe following example defines a comparer of Box objects that can be used instead of the default comparer. This example is part of a larger example provided for the Comparer<T> class. public class BoxLengthFirst : Comparer<Box> { // Compares by Length, Height, and Width. public override int Compare(Box x, Box y) { if (x.Length.CompareTo(y.Length) != 0) { return x.Length.CompareTo(y.Length); } else if (x.Height.CompareTo(y.Height) != 0) { return x.Height.CompareTo(y.Height); } else if (x.Width.CompareTo(y.Width) != 0) { return x.Width.CompareTo(y.Width); } else { return 0; } } } Public Class BoxLengthFirst Inherits Comparer(Of Box) ' Compares by Length, Height, and Width. Public Overrides Function Compare(ByVal x As Box, ByVal y As Box) As Integer If x.Length.CompareTo(y.Length) <> 0 Then Return x.Length.CompareTo(y.Length) ElseIf x.Height.CompareTo(y.Height) <> 0 Then Return x.Height.CompareTo(y.Height) ElseIf x.Width.CompareTo(y.Width) <> 0 Then Return x.Width.CompareTo(y.Width) Else Return 0 End If End Function End ClassRemarksImplement this method to provide a customized sort order comparison for type T. Notes to ImplementersComparing null with any reference type is allowed and does not generate an exception. A null reference is considered to be less than any reference that is not null. For information on culture-specific comparisons, see the System.Globalization namespace and Globalization and Localization. Applies to
|