Are there any considerations for immutable types regarding hash codes?
Do I have to generate it once, in the constructor?
How would you understand that the hash code has been fixed? Do I need to? If so, is it better to use the HashCode property instead of the GetHashCode method? Will there be a flaw in this? (Given that both will work, but the property will be recommended).
- ; - . , ; , -. ( , , , .)
, ?
; , ( ) . , , , . , , (1) , (2) .
, - ?
. -, . - . - , "" -, , - .
HashCode GetHashCode?
", GetHashCode(), , , - HashCode, "? ?
, .
, , , .
, , ? , . "" , .
, .NET Java String - Java ,.NET - . , , , , (, -). , .NET .
+ . , , . , (, ) , .
, , , . , - - , , . GetHashCode().
GetHashCode()
- , getHashCode , . , .
getHashCode
getHashCode , .
, GetHashCode(), , -. - - , . , ( ) ?
- - . , , , .
, " - " .
- GetHashCode().
, hashcode ? - , . , . GetHashCode, .
, , - , .
, HashCode . , .
If profiling really shows that GethashCode is taking a significant amount of time, you might need to cache it as a fix.
But I would not consider this a part of ordinary practice.