Comparing Objects in .Net – Reference Equality


Comparing two objects returns true if they point to the same entry of the

Public Class Person
   Private String Name;
   Private int Age;

   Public Person(String Name)
      this.Name = Name;

Class Program
      public static void Main(String[] args)
         Person P1 = new Person("John");
         Person P2 = new Person("Ron");
         Person P3 = P1;

        Console.WriteLine(P1 == P2);     // Prints False
        Console.WriteLine(P1 == P3);     // Prints True



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: