.NET Short Unique Identifier

前端 未结 23 1121
忘掉有多难
忘掉有多难 2020-12-07 11:27

I need a unique identifier in .NET (cannot use GUID as it is too long for this case).

Do people think that the algorithm used here is a good candidate or do you have

23条回答
  •  既然无缘
    2020-12-07 12:21

    var ticks = new DateTime(2016,1,1).Ticks;
    var ans = DateTime.Now.Ticks - ticks;
    var uniqueId = ans.ToString("x");
    

    Keep a baseline date (which in this case is 1st Jan 2016) from when you will start generating these ids. This will make your ids smaller.

    Generated Number: 3af3c14996e54

提交回复
热议问题