Guid.NewGuid().ToString()的几种格式

返回的字符串表示形式的值Guid实例,根据提供的格式说明符。

命名空间:   System
程序集:  mscorlib(位于 mscorlib.dll)

 

参数

format

Type: System.String

一个单格式说明符,它指示如何格式化此 Guid 的值。 format 参数可以是“N”、“D”、“B”、“P”或“X”。 如果 format 为 null 或空字符串 (""),则使用“D”。

返回值

Type: System.String

此 Guid 的值,用一系列指定格式的小写十六进制位表示。

 

备注

下表显示接受的格式说明符format参数。 "0"表示数字;连字符 ("-"),大括号 ("{","}"),和括号 ("(",")") 如下所示。

说明符

返回值的格式

N

32 位数字︰

00000000000000000000000000000000

D

连字符分隔的 32 位数字︰

00000000-0000-0000-0000-000000000000

B

由连字符,括在大括号分隔的 32 位数字︰

{00000000-0000-0000-0000-000000000000}

P

由括在括号中的连字符分隔的 32 位数字︰

(00000000-0000-0000-0000-000000000000)

X

四个十六进制值括在大括号,其中第四个值是也括在大括号的八个十六进制值的子集︰

{0x00000000、 0x0000、 0x0000,{0x00、 0x00 的、 0x00、 0x00 的、 0x00、 0x00 的、 0x00 的、 0x00}}

异常

ExceptionCondition
FormatException

format 的值不是 null、空字符串 ("")、“N”、“D”、“B”、“P”或“X”。

 

另请参阅

ToString 重载
Guid 结构
System 命名空间

可以对这段代码进行如下的优化: ``` if (theData.Id.IsNullOrEmpty()) { theData.Id = Guid.NewGuid().ToSequentialGuid(); if (theData.ifNeedVerifyCode == true && SessionHelper.Session["verifyCode"].IsNullOrEmpty()) { return Error("请先发送验证码"); } if (theData.ifNeedVerifyCode == true && SessionHelper.Session["verifyCode"].ToString() != theData.verifyCode) { return Error("验证码不正确"); } var unweightedCount = _wTapplicationBusiness.GetIQueryable() .Where(a => a.Carno == theData.Carno && a.ExpectedDate == theData.ExpectedDate && a.WeightTime.IsNullOrEmpty()) .Count(); if (unweightedCount > 0) { return Error("该车在该送货日期存在未过磅的信息,请过磅后再新增数据"); } _wTapplicationBusiness.AddData(theData); _wTapplicationBusiness.GetLogger().WriteOperateLog("WTapplication信息添加", "id:" + theData.Id, true); } else { var unweightedCount = _wTapplicationBusiness.GetIQueryable() .Where(a => a.Carno == theData.Carno && a.ExpectedDate == theData.ExpectedDate && a.WeightTime.IsNullOrEmpty() && a.Id != theData.Id) .Count(); if (unweightedCount > 0) { return Error("该车在该送货日期存在未过磅的信息,请过磅后再新增数据"); } _wTapplicationBusiness.UpdateData(theData); _wTapplicationBusiness.GetLogger().WriteOperateLog("WTapplication信息修改", "id:" + theData.Id, true); } ``` 主要的优化点如下: 1. 合并了两个 `if` 语句,使得代码更加简洁。 2. 重命名了 `UnWightCount` 变量为 `unweightedCount`,符合命名规范。 3. 将 `_wTapplicationBusiness.GetIQueryable()` 的查询条件提取出来,避免重复写代码。 4. 将新增和修改的代码分别写在了两个分支中,使得代码更加清晰易懂。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值