I’am implementing data serialization and I’ve encounter a problem.
I’ve got:
- 4 byte fields:
- Values range 0-255
- Values range 0- 4
- Values range 0-255
- Values range 0- 100
- and 1 int field(only positive values)
I’ve got an idea to convet all to byte array(lenght 8) or int array(lenght 2) and get C# GetHashCode method
Is GetHashCode strong enough to use as identifier for this data?
Or someone has better idea, maybe?
EOG
GetHashCode isn’t meant to create a unique identifier – its primary use is for assigning values to buckets in hashed data structures (like HashTable) – see http://ericlippert.com/2011/02/28/guidelines-and-rules-for-gethashcode/. When I need a unique identifier for an object, and for some reason the object itself doesn’t provide one, I usually just fall back on GUIDs. They are trivial to generate in C# and guaranteed to be unique within the scope of whatever you’re doing.