Int32.Equals() Method is used to get a value which indicates whether the current instance is equal to a specified object or Int32 or not. There are two methods in the overload list of this method as follows:
- Equals(Int32) Method
- Equals(Object) Method
Int32.Equals(Int32)
This method is used to return a value indicating whether the current instance is equal to a specified Int32 value or not.
Syntax: public bool Equals (int obj);
Here, it takes a Int32 value to compare to this instance.
Return Value: This method returns true if obj has the same value as this instance otherwise, false.
Below programs illustrate the use of
Int32.Equals(Int32) Method:
Example 1:
Output:
4562 is not equal to 2563
Example 2:
Output:
455 is not equal to 578
445 is equal to 445
10 is not equal to 20
2147483647 is not equal to -2147483648
Int32.Equals(Object) Method
This method is used to returns a value indicating whether the current instance is equal to a specified object or not.
Syntax: public override bool Equals (object obj);
Here, it takes an object to compare with this instance.
Return Value: This method returns true if obj is an instance of Int32 and equals the value of this instance otherwise, false.
Below programs illustrate the use of the above-discussed method:
Example 1:
Output:
10 is not equal to 0
Example 2: