一千萬個為什麽

搜索

c#是否與Java with equals和gethashcode()有相同的問題?

c#是否具有與equals和gethashcode相同的問題?

issues like: http://onjava.com/pub/a/onjava/2006/09/13/dont-let-hibernate-steal-your-identity.html

最佳答案

如果你的意思是在繼承方面很難定義平等,是的。

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

轉載註明原文: c#是否與Java with equals和gethashcode()有相同的問題?