System Namespace Object Class
Determines whether two Object instances are equal.
1. Determines whether the specified Object is equal to the current Object.
Determines whether the specified Object instances are considered equal.
[ C#, JScript ] The following code example compares different objects.
[ C#, JScript ] Note This example shows how to use one of the overloaded versions of
Equals. For other examples that might be available, see the individual overload topics.
[ C# ]
using System;
public class MyClass {
public static void Main ( ) {
string s1 = "Tom";
string s2 = "Carol";
Response.Write ( "Object.Equals ( \"{0}\", \"{1}\" ) => {2}",
s1, s2, Object.Equals ( s1, s2 ) );
s1 = "Tom";
s2 = "Tom";
Response.Write ( "Object.Equals ( \"{0}\", \"{1}\" ) => {2}",
s1, s2, Object.Equals ( s1, s2 ) );
s1 = null;
s2 = "Tom";
Response.Write ( "Object.Equals ( null, \"{1}\" ) => {2}",
s1, s2, Object.Equals ( s1, s2 ) );
s1 = "Carol";
s2 = null;
Response.Write ( "Object.Equals ( \"{0}\", null ) => {2}",
s1, s2, Object.Equals ( s1, s2 ) );
s1 = null;
s2 = null;
Response.Write ( "Object.Equals ( null, null ) => {2}",
s1, s2, Object.Equals ( s1, s2 ) );
}
}
/*
This code produces the following output.
Object.Equals ( "Tom", "Carol" ) => False
Object.Equals ( "Tom", "Tom" ) => True
Object.Equals ( null, "Tom" ) => False
Object.Equals ( "Carol", null ) => False
Object.Equals ( null, null ) => True
*/
[ JScript ]
import System
package Equals0
{
public class MyClass {
public static function Main ( ) {
var s1 : String = "Tom";
var s2 : String = "Carol";
var array : Object [ ] = new Object [ 3 ];
array [ 0 ] = s1;
array [ 1 ] = s2;
array [ 2 ] = System.Object.Equals ( s1, s2 );
Response.Write ( "Object.Equals ( '{0}', '{1}' ) => {2}",
array );
s1 = "Tom";
s2 = "Tom";
array [ 0 ] = s1;
array [ 1 ] = s2;
array [ 2 ] = System.Object.Equals ( s1, s2 );
Response.Write ( "Object.Equals ( '{0}', '{1}' ) => {2}",
array );
s1 = null;
s2 = "Tom";
array [ 0 ] = s1;
array [ 1 ] = s2;
array [ 2 ] = System.Object.Equals ( s1, s2 );
Response.Write ( "Object.Equals ( null, '{1}' ) => {2}",
array );
s1 = "Carol";
s2 = null;
array [ 0 ] = s1;
array [ 1 ] = s2;
array [ 2 ] = System.Object.Equals ( s1, s2 );
Response.Write ( "Object.Equals ( '{0}', null ) => {2}",
array );
s1 = null;
s2 = null;
array [ 0 ] = s1;
array [ 1 ] = s2;
array [ 2 ] = System.Object.Equals ( s1, s2 );
Response.Write ( "Object.Equals ( null, null ) => {2}",
array );
}
}
}
Equals0.MyClass.Main ( );
/*
This code produces the following output.
Object.Equals ( "Tom", "Carol" ) => False
Object.Equals ( "Tom", "Tom" ) => True
Object.Equals ( null, "Tom" ) => False
Object.Equals ( "Carol", null ) => False
Object.Equals ( null, null ) => True
*/
Object Members