直接用.NET Framework 提供的 Guid() 函数:

Guid.NewGuid()是指生成唯一码的规则

System.Guid.NewGuid().ToString()全球唯一标识符 (GUID) 是一个字母数字标识符

 

System.Guid.NewGuid().ToString(format):生成的ID值的格式:

说明符       返回值的格式  
 
N                  32   位:  

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx  
 
D                  由连字符分隔的   32   位数字:  

xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx  
 
B                  括在大括号中、由连字符分隔的   32   位数字:  

{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}  
 
P                  括在圆括号中、由连字符分隔的   32   位数字:  

(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)  

Guid guid = Guid.NewGuid();
string id = guid.ToString("N");

保存到数据库中后,就是一串32位的字符串

 

相关文章:

  • 2021-08-13
  • 2021-10-27
  • 2022-01-19
  • 2021-09-16
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-21
  • 2022-12-23
  • 2022-12-23
  • 2021-12-07
  • 2022-12-23
  • 2022-12-23
  • 2021-08-25
相关资源
相似解决方案