C#使用GUID(全局统一标识符)

  class Program

  {

  static void Main(string[] args)

  {

  var uuid = Guid.NewGuid().ToString(); // 67b69599-5026-4765-8707-def49a214219

  var uuidN = Guid.NewGuid().ToString("N"); // f93618e93beb4a4181526d7a38c169a4

  var uuidD = Guid.NewGuid().ToString("D"); //c747ac63-a9c2-46f9-80d7-f635c330a59f

  var uuidB = Guid.NewGuid().ToString("B"); // {2a77d03e-0366-4977-97f1-229c17fe906f}

  var uuidP = Guid.NewGuid().ToString("P"); // (8165193f-8595-439d-bbaf-9ce55171eecf)

  var uuidX = Guid.NewGuid().ToString("X"); // {0x48645e66,0xbe0c,0x4990,{0x8e,0xee,0x3c,0x84,0xba,0xda,0x0d,0x83}}

  var guid1 = GenerateId1();//5a0aec9398c64e09

  var guid2 = GenerateId2();//4976172849618296785

  }

  private static string GenerateId1()

  {

  long i = 1;

  foreach (byte b in Guid.NewGuid().ToByteArray())

  {

  i *= ((int)b + 1);

  }

  return string.Format("{0:x}", i - DateTime.Now.Ticks);

  }

  private static long GenerateId2()

  {

  byte[] buffer = Guid.NewGuid().ToByteArray();

  return BitConverter.ToInt64(buffer, 0);

  }

  }