anonim - 10 months ago 56
C# Question

# How generate unique Integers based on GUIDs

Is it possible to generate (highly probable) unique Integer from GUIDs?

int i = Guid.NewGuid().GetHashCode();

int j = BitConverter.ToInt32(Guid.NewGuid().ToByteArray(), 0);


Which one is better?

Related to your specific question, I would also go with GetHashCode since collisions will be unavoidable either way.