C# Guid 16位 唯一
时间:2017-06-13 13:33:30
收藏:0
阅读:494
public static class GuidExtentions { /// <summary> /// 根据GUID获取16位的唯一字符串 /// </summary> /// <param name="guid"></param> /// <returns></returns> public static string To16String(this Guid guid) { var i = guid.ToByteArray().Aggregate<byte, long>(1, (current, b) => current* (b + 1)); return $"{i - DateTime.Now.Ticks:x}"; } /// <summary> /// 根据GUID获取19位的唯一数字序列 /// </summary> /// <returns></returns> public static long ToInt64(this Guid guid) { var buffer = guid.ToByteArray(); return BitConverter.ToInt64(buffer, 0); } }
使用:
var guid=Guid.NewGuid().To16String();
原文:http://www.cnblogs.com/gaobing/p/7000567.html
评论(0)