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.)
Answer: See the explanation
And you would need to return true at the end…
5,7,1
Anyone can explain why “if(!this.Name.Equals(other.Name)) return false” can’t be used?
if this.Name is null it will throw an exception
Object.Equals(….) internally checks if the received objects are null or in different types and return false.
5,7,1,4
any reason why we include if(other ==null) return false ? i assume it is to prevent an exception. but why are we not checking this.name if it is null?
are we only checking other==null to ensure that they are not equal as one is null
If this.Name is null, calling .Equals() on it will result in a NullReferenceException.