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

System.Guid.NewGuid().ToString()全球唯一标识符(GUID) 是一个字母数字标识符,用于指示产品的唯一性标识
public string ToString(
    string format
)
参数
format
类型: System.String
一个单格式说明符,它指示如何格式化此 Guid 的值。 format 参数可以是“N”、“D”、“B”、“P”或“X”。 如果 format 为 null 或空字符串 (""),则使用“D”。 
返回值
类型: 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

括在大括号的 4 个十六进制值,其中第 4 个值是 8 个十六进制值的子集(也括在大括号中):

{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}

十六进制数字 a 到 f 是例在返回的字符串。 若要将它们转换为大写,请调用在返回的字符串的 String.ToUpper 方法。

 

转载于:https://www.cnblogs.com/xcsn/p/4246588.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以对这段代码进行如下的优化: ``` 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、付费专栏及课程。

余额充值