C#中GUID的生成以及格式
来源:互联网 发布:淘宝店铺修改发货地址 编辑:程序博客网 时间:2024/05/20 02:23
1、GUID是在System命名空间下的结构(struct)体,下面展示实例。
(1)创建一个GUID帮助类(GUIDHelper)
using System;using System.Collections.Generic;using System.Linq;using System.Web;namespace WebDemo.guid{ public class GuIdHelper { /// <summary> /// GUID生成 /// </summary> /// <param name="format">格式 可填写N、D、B、P、X</param> /// <returns></returns> public static string GetNewGuId(string format="") { if (string.IsNullOrWhiteSpace(format)) return Guid.NewGuid().ToString(); else return Guid.NewGuid().ToString(format); } }}
(2)使用实例
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Text;namespace WebDemo.guid{ public partial class Index : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { StringBuilder str = new StringBuilder(); string[] array = {"","N","D","B","P","X" }; foreach (var item in array) { if (string.IsNullOrWhiteSpace(item)) str.AppendFormat("默认格式:{0}", GuIdHelper.GetNewGuId()); else str.AppendFormat("<br />{0}格式:{1}", item, GuIdHelper.GetNewGuId(item)); } Response.Write(str.ToString()); } }}
(3)显示结果
默认格式:4575c4b3-7997-4f11-acd9-f107258e9adcN格式:a53a7186b583483aa4580519034e8095D格式:5ae7f002-a989-4345-864b-3bcfbe09e1daB格式:{d9762660-8461-4c44-b714-8ffad6e1b79c}P格式:(694ce704-0a7d-41d5-a25a-4eaedf7db50d)X格式:{0x75198f26,0xac4e,0x42c8,{0x96,0x88,0xcc,0x91,0xe0,0xa6,0x9b,0x21}
1 0
- C#中GUID的生成以及格式
- C# 中GUID生成格式的四种格式
- C# 中GUID生成格式的四种格式
- C# 中GUID生成格式的四种格式
- C# 中GUID生成格式的四种格式
- 在C#中GUID生成的四种格式
- 在C#中GUID生成的四种格式
- 在C#中GUID生成的四种格式
- C#中的GUID生成格式
- 在C#中GUID生成的四种格式具体案例
- C# 和SQL server 中生成GUID 的方法 以及他们的之间的区别
- C++Builder 生成 GUID 以及在IDE中生成GUID
- C#和sqlserver中生成新的32位GUID
- C#和sqlserver中生成新的32位GUID
- c#中Guid的作用
- C#生成GUID
- C#生成Guid
- ASP中生成GUID的方法一种
- SQL基础(1):数据定义
- Android使用本地Service实现后台播放音乐
- linux-----遇到的问题----tab键不补全sh文件不能运行
- JSTL SQL 标签库
- JavaBean的定义规范和原因
- C#中GUID的生成以及格式
- 递归调用:汉诺塔
- Matlab中的几个随机函数-randperm,sort,rand,randint
- 终于有人把O2O、C2C、B2B、B2C的区别讲透了
- 腾讯云服务器装MYSQL数据库浏览器访问乱码问题
- 如何高效的访问内存
- 左值引用与右值引用
- 前端开发案例——COOKIE/SESSION机制(一)
- How to Estimate Export File Size Without Creating Dump File