Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Type.Equals Method

Determines if the underlying system type of the current Type is the same as the underlying system type of the specified Object or Type.

Overload List

Determines if the underlying system type of the current Type is the same as the underlying system type of the specified Object.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Overrides Public Function Equals(Object) As Boolean
[C#] public override bool Equals(object);
[C++] public: bool Equals(Object*);
[JScript] public override function Equals(Object) : Boolean;

Determines if the underlying system type of the current Type is the same as the underlying system type of the specified Type.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function Equals(Type) As Boolean
[C#] public bool Equals(Type);
[C++] public: bool Equals(Type*);
[JScript] public function Equals(Type) : Boolean;

Example

The following example uses Equals to compare two types.

[Visual Basic] 
Imports System
Imports System.Reflection

Class EqType
    
    Public Shared Sub Main()
        Dim a As Integer = 1
        Dim b As Single = 1
        Console.WriteLine("{0}", a.Equals(b).ToString())
        b = a
        Console.WriteLine("{0}", a.Equals(b).ToString())
    End Sub
End Class

'This code produces the following output:
'False
'False

[C#] 
using System;
using System.Reflection;

class EqType
{
  public static void Main(String[] args)
  {
   int a = 1;
   float b = 1;
   Console.WriteLine("{0}", a.Equals(b).ToString());
   b=a;
   Console.WriteLine("{0}", a.Equals(b).ToString());
  }
}

//This code produces the following output:
//False
//False

[C++] 
#using <mscorlib.dll>
using namespace System;
using namespace System::Reflection;

int main()
{
    int a = 1;
    float b = 1;
    Console::WriteLine(S"{0}", __box(a.Equals(__box(b))));
    b = (float)a;
    Console::WriteLine(S"{0}", __box(a.Equals(__box(b))));
}

//This code produces the following output:
//False
//False

[JScript] 
import System;
import System.Reflection;

class EqType
{
  public static function Main() : void 
  {
   var a : int= 1;
   var b : float = 1;
   Console.WriteLine("{0}", a.Equals(b).ToString());
   b=float(a);
   Console.WriteLine("{0}", a.Equals(b).ToString());
  }
}
EqType.Main();
//This code produces the following output:
//False
//False

See Also

Type Class | Type Members | System Namespace

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.