次の方法で共有


Type.Equals メソッド

現在の Type の基になるシステム型が、指定した Object または Type の基になるシステム型と同じかどうかを判断します。

オーバーロードの一覧

現在の Type の基になるシステム型が、指定した Object の基になるシステム型と同じかどうかを判断します。

.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;

現在の Type の基になるシステム型が、指定した Type の基になるシステム型と同じかどうかを判断します。

.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;

使用例

Equals を使用して 2 つの型を比較するコード例を次に示します。

 
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

参照

Type クラス | Type メンバ | System 名前空間