Sandhurst
Sandhurst

Reputation: 237

Generate Unique ID following a specific pattern like "digitStringDigit" in C#

I have earlier generated unique ids by making use of Math.Rando, method or sometimes by using GUID.NewGUID method. This time I am trying to generate a unique numbers which are based on a specific pattern.

for instance 123ABC123 - the length of the number will always remain 9 and it will contain 3 numeric digits followed by three characters and then followed by three more digits.

Upvotes: 2

Views: 1938

Answers (1)

Michael Eakins
Michael Eakins

Reputation: 4179

If I wanted a purely unique ID I would use:

 TimeSpan uniqueID = DateTime.Now.ticks;

Which guarnatees you get a unique ID regardless of when you call it.

Upvotes: 2

Related Questions