You need to implement IEquatable

DRAG DROP
You have the following class:

You need to implement IEquatable. The Equals method must return true if both ID and Name are set to the
identical values. Otherwise, the method must return false. Equals must not throw an exception.
What should you do? (Develop the solution by selecting and ordering the required code snippets. You may not
need all of the code snippets.)
Select and Place:

DRAG DROP
You have the following class:

You need to implement IEquatable. The Equals method must return true if both ID and Name are set to the
identical values. Otherwise, the method must return false. Equals must not throw an exception.
What should you do? (Develop the solution by selecting and ordering the required code snippets. You may not
need all of the code snippets.)
Select and Place:

Answer:



Leave a Reply 2

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


f9p

f9p

1 – if (other == null) return false;
2 – if (this.ID != other.ID) return false;
3 – if (!Object.Equals(this.Name, other.Name)) return false;
3 – if (!this.Name.Equals(other.Name)) return false;
(Both are correct)
4 – return true;

f9p

f9p

Sorry, if (!Object.Equals(this.Name, other.Name)) return false; is correct becuase Name could be null.