1. 程式人生 > >[.Net] - 生成短 Guid 標識符的方法

[.Net] - 生成短 Guid 標識符的方法

each 生成 clas 資料 tco htm .com str array

產生字符串(例:49f949d735f5c79e)

private string GenerateId()
{
    long i = 1;
    foreach (byte b in Guid.NewGuid().ToByteArray())
    {
        i *= ((int)b + 1);
    }
    return string.Format("{0:x}", i - DateTime.Now.Ticks);
}

產生 Int64 類型(例:4833055965497820814)

private long GenerateId()
{
    byte[] buffer = Guid.NewGuid().ToByteArray();
return BitConverter.ToInt64(buffer, 0); }

參考資料

http://www.cnblogs.com/SUNBOY/archive/2008/07/24/1250797.html

[.Net] - 生成短 Guid 標識符的方法