C# Guid.ToString参数总结

Guid是C#标准库提供的GUID生成器,并且ToString方法支持参数传入:N、D、B、P、X,并输出不同的结果。

代码

		  Guid guid = Guid.NewGuid();
		  var tmp = guid.ToString();
		  Console.WriteLine(tmp);
		  
		  tmp = guid.ToString("N");
		  Console.WriteLine(tmp);
		  
		  tmp = guid.ToString("D");
		  Console.WriteLine(tmp);
		  
		  tmp = guid.ToString("B");
		  Console.WriteLine(tmp);
		  
		  tmp = guid.ToString("P");
		  Console.WriteLine(tmp);
		  
		  tmp = guid.ToString("X");
		  Console.WriteLine(tmp);

输出

		  3bd1535c-cb37-4a73-918b-5a23a4a4eb67
		  3bd1535ccb374a73918b5a23a4a4eb67
		  3bd1535c-cb37-4a73-918b-5a23a4a4eb67
		  {3bd1535c-cb37-4a73-918b-5a23a4a4eb67}
		  (3bd1535c-cb37-4a73-918b-5a23a4a4eb67)
		  {0x3bd1535c,0xcb37,0x4a73,{0x91,0x8b,0x5a,0x23,0xa4,0xa4,0xeb,0x67}}
# c#   guid  

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×