当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > Creating GUIDs in c#

ASP.NET
.NET中如何生成静态页
ASP.NET定制简单的错误处理页面
在客户端验证密码强度[2],兼容FireFox和IE
如何以及为何创建Search .NET版
ASP.NET十分有用的页面间传值方法
使用ASP.NET AJAX框架扩展HTML Map控件
AJAX使用技巧:如何处理书签和翻页按扭
.NET环境下几种不同的邮件发送解决方案
.NET vs J2EE——面对SOA的荒谬与误解
ASP.NET学习篇(1)——开篇
ASP.NET学习篇(2)——安装与配置
ASP.NET学习篇(3)——几个简单的ASP.ENT的例子
ASP.NET学习篇(4)——服务器端的控件
项目调试时出现用到的一个组件“访问被拒绝”的解决方法
ASP.NET中“找不到指定模块”的解决办法
采用Native 引导方式的.Net加密保护
“您无权查看该网页”的原因和解决方法
ASP.NET中Datagrid常见错误
编写ASP.NET应用程序的技巧
Scott Mitchell ASP.NET 2数据控件嵌套

ASP.NET 中的 Creating GUIDs in c#


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 212 ::
收藏到网摘: n/a

What is a GUID
For those of you who don''t know, a GUID (pronounced goo''id - Globally unique identifier) is a 128-bit integer that can be used to uniquely identify something. You may store users or products in your database and you want somehow uniquely identify each row in the database. A common approach is to create a autoincrementing integer, another way would be to create a GUID for your products.
How to create a GUID in C#
The GUID method can be found in the System namespace. The GUID method System.Guid.NewGuid() initializes a new instance of the GUID class.
There are also a few overloads available for those of you who want the GUID formatted in a particular fashion.
The following live sample will output the GUID generated, the source code is also below.
Response.Write(@"
System.Guid.NewGuid().ToString() = " + System.Guid.NewGuid().ToString());
Response.Write(@"

System.Guid.NewGuid().ToString(""N"") = " + System.Guid.NewGuid().ToString("N"));
Response.Write(@"
System.Guid.NewGuid().ToString(""D"") = " + System.Guid.NewGuid().ToString("D"));
Response.Write(@"
System.Guid.NewGuid().ToString(""B"") = " + System.Guid.NewGuid().ToString("B"));
Response.Write(@"
System.Guid.NewGuid().ToString(""P"") = " + System.Guid.NewGuid().ToString("P"));