Practice mode C#

Given record Point(int X, int Y);, what does Console.WriteLine(new Point(1, 2) == new Point(1, 2)); print?

Correct answer A. True

Explanation

Records have compiler-generated value-based equality: two instances are equal when they are the same type and all their properties are equal. So the two Point objects compare equal and the program prints True, even though they are separate objects. An ordinary class would use reference equality and print False. Records also generate a readable ToString.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.