这篇文章主要介绍了asp.net system.guid tostring五种格式,需要的朋友可以参考下
参考:https://msdn.microsoft.com/en-us/library/97af8hh4.aspx
测试代码:
using system;
using system.collections.generic;
using system.linq;
using system.text;
namespace guidtostring
{
class program
{
static void main(string[] args)
{
console.writeline(" -->" + system.guid.newguid().tostring());
console.writeline("n-->" + system.guid.newguid().tostring("n"));
console.writeline("d-->" + system.guid.newguid().tostring("d"));
console.writeline("b-->" + system.guid.newguid().tostring("b"));
console.writeline("p-->" + system.guid.newguid().tostring("p"));
console.writeline("x-->" + system.guid.newguid().tostring("x"));
console.readkey();
}
}
}
测试结果:
注意事项:只能使用n、d、b、p、x(不区分大小写)空,使用其他字母会出现异常
格式字符串只能是“d”、“d”、“n”、“n”、“p”、“p”、“b”、“b”、“x”或“x”。
异常情况:
以下都正常:
using system;
using system.collections.generic;
using system.linq;
using system.text;
namespace guidtostring
{
class program
{
static void main(string[] args)
{
console.writeline(" -->" + system.guid.newguid().tostring());
console.writeline(" -->" + system.guid.newguid().tostring(""));
console.writeline("n-->" + system.guid.newguid().tostring("n"));
console.writeline("n-->" + system.guid.newguid().tostring("n"));
console.writeline("d-->" + system.guid.newguid().tostring("d"));
console.writeline("d-->" + system.guid.newguid().tostring("d"));
console.writeline("b-->" + system.guid.newguid().tostring("b"));
console.writeline("b-->" + system.guid.newguid().tostring("b"));
console.writeline("p-->" + system.guid.newguid().tostring("p"));
console.writeline("p-->" + system.guid.newguid().tostring("p"));
console.writeline("x-->" + system.guid.newguid().tostring("x"));
console.writeline("x-->" + system.guid.newguid().tostring("x"));
console.readkey();
}
}
}
guid.newguid().tostring()的几种格式
1、guid.newguid().tostring(n) 结果为:
38bddf48f43c48588e0d78761eaa1ce6
2、guid.newguid().tostring(d) 结果为:
57d99d89-caab-482a-a0e9-a0a803eed3ba
3、guid.newguid().tostring(b) 结果为:
{09f140d5-af72-44ba-a763-c861304b46f8}
4、guid.newguid().tostring(p) 结果为:
(778406c2-efff-4262-ab03-70a77d09c2b5)
更多asp.net system.guid tostring五种格式。