当前位置: 动力学知识库 > 问答 > 编程问答 >

c# 4.0 - IComparer or IEquatable or niether?

问题描述:

I have two different types, TypeA and TypeB, both of which are relatable in the sense that they describe the same concept but from different view points - though there exists a loose temporal relationship.

I want to create a utility method which tests to see if the two types I pass into the utility method are in fact related.

The objects are not directly equitable, but I thought that they might be Comparable (which they are), however when I look at the description of ICompareable, it suggest that this should be implemented to assist sorting of arrays.

Is there a better interface to use, or should I just create my own comparer routine which does not implement any interface. This is what I am going with for now, but I thought there might be a more pattern specific solution, hence the question.

网友答案:

I would go for an own solution, as neither IComparer nor IEquatable are matching your requirement.

Maybe just bool IsRelatedTo() instance method would be enough?

分享给朋友:
您可能感兴趣的文章:
随机阅读: