开发者

Does c# have the same issues like Java with equals and gethashcode()?

Does c# have the same issues like Java with equals and gethashcode?

issues like: http://onjava.com/pub/a/onjava/20开发者_JS百科06/09/13/dont-let-hibernate-steal-your-identity.html


If you mean that equality is hard to define when it comes to inheritance, yes.

However, .NET has the IEqualityComparer<T> interface which is frequently used for equality and hashing - for containers such as Dictionary<TKey, TValue>. Almost everything in the framework which needs equality/hashing allows the behaviour to be specified by an IEqualityComparer<T>, which means you can express whichever notion of equality you want, if the form given by the type itself is inappropriate for your needs.


Not sure which issues you're talking about since you're a little vague...

But if you mean that you have should (if you don't want a compiler warning, or possibly unexpected behavior in your code) to override GetHashCode when you override Equals, then yes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜