When To Use IEquatable And Why

后端 未结 5 806
天命终不由人
天命终不由人 2020-12-07 17:31

What does IEquatable buy you, exactly? The only reason I can see it being useful is when creating a generic type and forcing users to implement and write a good equ

5条回答
  •  春和景丽
    2020-12-07 18:03

    I use IEquatable quite a lot, although from a pure technical perspective, it doesn't really give me any particular benefits. Overriding System.Object.Equals can provide you with the same functionality.

    However, I like the explicitness of implementing IEquatable. I use the concepts of Entities and Value Objects from Domain-Driven Design quite a lot, and use IEquatable particularly for Value Objects, simply because it signals that a type has well-defined equality.

提交回复
热议问题