I have a string that I would like represented uniquely as an integer.
For example: A3FJEI = 34950140
How would I go about writing a EncodeAsInteger(string) method. I understand that the amount of characters in the string will make the integer increase greatly, forcing the value to become a long, not an int.
Since I need the value to be an integer, I don’t need the numerical representation to be entirely unique to the string.
Maybe I can foreach through all the characters of the string and sum the numerical keycode of the character.
If these are your requirements:
Then you’re in luck, because this is exactly what the
GetHashCode()method does! The MSDN page gives some sample hash codes. Note that these are completely arbitrary and can change in future versions of the CLR.