Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Int32.Equals Method

Returns a value indicating whether this instance is equal to a specified object.

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

Parameters

obj
An object to compare with this instance.

Return Value

true if obj is an instance of Int32 and equals the value of this instance; otherwise, false.

Example

[Visual Basic, C#, C++] The following code sample illustrates the use of Equals in the context of Int32, comparing two int values and returning true if they represent the same number, or false if they do not.

[Visual Basic] 
Dim myVariable1 As Int32 = 60
Dim myVariable2 As Int32 = 60

' Get and display the declaring type.
Console.WriteLine(ControlChars.NewLine + "Type of 'myVariable1' is '{0}' and" +  _
         " value is :{1}", myVariable1.GetType().ToString(), myVariable1.ToString())
Console.WriteLine("Type of 'myVariable2' is '{0}' and" +  _
         " value is :{1}", myVariable2.GetType().ToString(), myVariable2.ToString())

' Compare 'myVariable1' instance with 'myVariable2' Object.
If myVariable1.Equals(myVariable2) Then
   Console.WriteLine(ControlChars.NewLine + "Structures 'myVariable1' and " +  _
            "'myVariable2' are equal")
Else
   Console.WriteLine(ControlChars.NewLine + "Structures 'myVariable1' and " + _
         "'myVariable2' are not equal")
End If

[C#] 
Int32 myVariable1 = 60;
Int32 myVariable2 = 60;

// Get and display the declaring type.
Console.WriteLine("\nType of 'myVariable1' is '{0}' and"+
     " value is :{1}",myVariable1.GetType(), myVariable1); 
Console.WriteLine("Type of 'myVariable2' is '{0}' and"+
     " value is :{1}",myVariable2.GetType(), myVariable2);

// Compare 'myVariable1' instance with 'myVariable2' Object.
if( myVariable1.Equals( myVariable2 ) )
   Console.WriteLine( "\nStructures 'myVariable1' and "+
         "'myVariable2' are equal");
else
   Console.WriteLine( "\nStructures 'myVariable1' and "+
         "'myVariable2' are not equal");


[C++] 
Int32 myVariable1 = 60;
Int32 myVariable2 = 60;

// Get and display the declaring type.
Console::WriteLine(S"\nType of 'myVariable1' is '{0}' and  value is : {1}", __box(myVariable1)->GetType(), __box(myVariable1));
Console::WriteLine(S"Type of 'myVariable2' is '{0}' and  value is : {1}", __box(myVariable2)->GetType(), __box(myVariable2));

// Compare 'myVariable1' instance with 'myVariable2' Object.
if (__box(myVariable1)->Equals(__box(myVariable2)))
   Console::WriteLine(S"\nStructures 'myVariable1' and 'myVariable2' are equal");
else
   Console::WriteLine(S"\nStructures 'myVariable1' and 'myVariable2' are not equal");

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

Int32 Structure | Int32 Members | System Namespace | CompareTo

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft