Skip to main content

What is the difference between equality operator and reference equality?

Mid C#
Quick Answer For reference types, == by default checks if two variables point to the same object in memory. object.ReferenceEquals() always does this. But classes can override == and Equals() to compare by content. String does exactly this รขโ‚ฌโ€ two different string objects with the same text are ==.

Answer

Equality operator: Checks logical equality when overridden.

Reference equality: Checks if two references point to the same object instance.

S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice