How do I create an identifier that is required in order to be unique?
I need to use the uniqueness of the id. Even if you have a 1 in 1 trillion chance, but I can't use it.
But I really don't feel like going to the ends of the earth to find a solution. I've spent some time researching this and everything I've found to date cannot guarantee me a unique ID.
So, I thought I would be using something very simple like:
public static string GenerateItemID()
{
string year = DateTime.Now.Year.ToString(),
month = DateTime.Now.Month.ToString(),
day = DateTime.Now.Day.ToString(),
hour = DateTime.Now.Hour.ToString(),
minute = DateTime.Now.Minute.ToString(),
second = DateTime.Now.Second.ToString(),
millisecond = DateTime.Now.Millisecond.ToString();
return year + month + day + hour + minute + second + millisecond;
}
My logic is here: every new user interface that is generated cannot be the same as any of the previous ones. But then I thought, is it possible for a PC to be able to generate two or more of these IDs in one millisecond? Naturally I was then looking for Intellisense for the Nanosecond property, but it doesn't exist.
How can I generate a garunteed id to be unique?
source to share
Use a GUID.
See here: https://msdn.microsoft.com/en-us/library/system.guid.newguid(v=vs.110).aspx
Hope for this help.
source to share