Given two different strings, is it always the case that s.GetHashCode() != s1.GetHashCode()?
Is it the case that the number of distinct integers is less than the number of distinct strings?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No. Just as a simple thought experiment: How many strings are there (hint: many more than 232 and thus how many unique hash codes can there be (hint: 232. See the problem?)
Hash codes are just required to be equal whenever
Equalsreturns that both objects are equal. Furthermore, whenever two hash codes are not equal, then the objects themselves cannot be equal. There is no further requirement, but they should be well-distributed so that hash tables can perform well. So basically it’s:Note the omission of the respective ⇐ variants. It’s not an equivalence, just two implications.
To quote the documentation: