Showing Tag: "unique" (Show all posts)

Generating Unique ID in C# - Best Method.

Posted by jineesh uvantavida on Friday, November 10, 2017, In : c# 

We can use DateTime.Now.Ticks and Guid.NewGuid().ToString() to combine together and make a unique id.

As the DateTime.Now.Ticks is added, we can find out the Date and Time in seconds at which the unique id is created.

Please see the code.

var ticks = DateTime.Now.Ticks;
var guid = Guid.NewGuid().ToString();
var uniqueSessionId = ticks.ToString() +'-'+ guid; //guid created by combining ticks and guid

var datetime = new DateTime(ticks);//for checking purpose
var datetimenow = DateTime.Now;    //b...

Continue reading ...
 
 

Translate This Page

 


Make a free website with Yola