I’m looking for a method of generating unique identifiers for a record class being created locally and then persisted in various formats (XML, SQL, etc.)
I’ve seen people using DateTime and GetHashCode, but that seems to lend itself to duplicate identifiers depending upon the sample size.
GUID is a bit overkill, as I don’t need anything that unique (large) at the global level. I’m also aware of using GUIDs and GetHashCode to get the size down a bit, but duplicates tend to crop up here as well.
Can anyone suggest a best practice or method for generating simple unique identifiers?
Guid or increasing counter.
Guid can be generated “from air” but takes more space
For counter you need to store the counter somewhere and you will need to make it thread safe if you use threads. But it is smaller in size.