c# - How do I generate an ID that is garunteed to be unique? -
this question has answer here:
- unique random string generation 11 answers
i need garuntee uniqueness of id. if there's 1 in 1 trillion chance of there being dupe, cannot use it.
but don't feel going ends of earth find solution either. have spent time looking this, , have found date isn't able garuntee me unique id.
so thought use simple, this:
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 here is: each new ui generated can not possibly same of previous ones. wondered if possible pc generate 2 or more of these id's within same millisecond? naturally, looked in intellisense nanosecond property, doesn't exist.
how can generate id garunteed unique?
var id = guid.newguid();
i believe create unique id.
Comments
Post a Comment