FAQ: The Object Class - Object Members

This community-built FAQ covers the " Object Members" exercise from the lesson “The Object Class”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn C#

FAQs on the exercise _ Object Members_

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in #get-help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to #get-help and #community:tips-and-resources. If you are wanting feedback or inspiration for a project, check out #project.

Looking for motivation to keep learning? Join our wider discussions in #community

Learn more about how to use this guide.

Found a bug? Report it online, or post in #community:Codecademy-Bug-Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Hi. I’m not entirely sure but I think there’s a mistake in this lesson: Object Members

I believe this is incorrect: “referential equality for reference types”.

  • Equals(Object) — returns true if the current instance and the argument are equal (using value equality for value types and referential equality for reference types)

There are two overloads for Equals method (Equals(Object) and Equals(Object, Object)) and they both seem to perform value/type comparison.

For reference comparison one should use Reference.Equals(Object, Object)

See examples from Microsoft docs

public static void Main()
  {
     Point3D point3Da = new Point3D(5, 5, 2);
     Point3D point3Db = new Point3D(5, 5, 2);
     Point3D point3Dc = new Point3D(5, 5, -1);

     Console.WriteLine("{0} = {1}: {2}",
                       point3Da, point3Db, point3Da.Equals(point3Db));
     Console.WriteLine("{0} = {1}: {2}",
                       point3Da, point3Dc, point3Da.Equals(point3Dc));
  }

//Point(5, 5, 2) = Point(5, 5, 2): True
//Point(5, 5, 2) = Point(5, 5, -1): False
      Dog m1 = new Dog("Alaskan Malamute");
      Dog m2 = new Dog("Alaskan Malamute");
      Dog g1 = new Dog("Great Pyrenees");
      Dog g2 = g1;
      Dog d1 = new Dog("Dalmation");

      Console.WriteLine("{0} = {1}: {2}", g1, g2, Object.Equals(g1, g2));
      Console.WriteLine("{0} Reference Equals {1}: {2}\n", g1, g2, Object.ReferenceEquals(g1, g2));

      Console.WriteLine("{0} = {1}: {2}", m1, m2, Object.Equals(m1, m2));
      Console.WriteLine("{0} Reference Equals {1}: {2}\n", m1, m2, Object.ReferenceEquals(m1, m2));

      Console.WriteLine("{0} = {1}: {2}", m1, d1, Object.Equals(m1, d1));
      Console.WriteLine("{0} Reference Equals {1}: {2}", m1, d1, Object.ReferenceEquals(m1, d1));


// Great Pyrenees = Great Pyrenees: True
// Great Pyrenees Reference Equals Great Pyrenees: True

// Alaskan Malamute = Alaskan Malamute: True
// Alaskan Malamute Reference Equals Alaskan Malamute: False

// Alaskan Malamute = Dalmation: False
// Alaskan Malamute Reference Equals Dalmation: False

It is a good question, not a mistake though. There is a semantic difference between Equals and ReferenceEquals(Object,Object):

  1. and most importantly ReferenceEquals(Object,Object) is a STATIC method - as your example from documentation shows it’s called with a class Object, not with an instance.
  2. ReferenceEquals(Object,Object) CANNOT be overriden.
  3. ReferenceEquals(Object,Object) CAN ONLY have two arguments, however - they CAN be null and it will never throw NullReferenceException.
  4. Equals works ONLY on object instances
  5. Equals CANNOT be called on null or unassigned reference.
  6. Equals can be overriden.

Basically ReferenceEquality is the same thing as == and yes it should be used with references. HOWEVER, this will not always be possible. You will see Equals more often since it’s one of the most commonly overriden methods…

So I wouldn’t say it was a mistake on their part, but I agree it should be explicitly pointed out to seek for ReferenceEquals inside documentation.

1 Like