C # generate a Globally Unique Identifier

Source: Internet
Author: User
A globally unique identifier is composed of a 128-bit integer. You can use it to access any computer that requires a unique identifier or any network that requires a unique identifier. Tony Patton explains how. NET Framework teaches you how to create your own globally unique identifier.
Free of techrepublic. net newsletters are published on Wednesday, discussing such topics as Web Services and ASP. net, ADO. and Visual Studio. net, which provides some useful prompts and coding examples. You can subscribe now.

When Windows developers need a unique value, they usually use a globally unique identifier. Microsoft uses the Globally Unique Identifier (guid) to describe a unique number. It can recognize an entity such as word text.

A globally unique identifier consists of a 128-bit integer (16 bytes) that you can use to access any computer that requires a unique identifier or any network that requires a unique identifier. This type of identifier may be copied very little.

This article explains how. NET Framework helps you create your own globally unique identifier.

Wherever you are, you will see that globally unique identifiers are always operated in windows. When you carefully read the Registry in Windows, you will find that globally unique identifiers are widely used to identify applications.ProgramAnd so on. In hkey_classes_root, it is even used as the application identifier. Http://www.downcodes.com/

936da01f-9abd-4d9d-80c7-02af85c822a8 is a typical globally unique identifier format.

Create a globally unique identifier with. net

With a globally unique identifier, you can easily store or retrieve information. This feature is even more prominent when it comes to databases, because globally unique identifiers can help you set an excellent primary key.

Similarly, SQL Server supports globally unique identifiers, which can store a globally unique identifier of the uniqueidentifier data type. You can use the newid () function to set an Identifier value in SQL Server, or you can set an Identifier value in other systems before manually inserting the value into SQL Server.

The last method in. NET is straightforward .. The basic system classes in the. NET framework include the value types of globally unique identifiers. In addition, this value type includes the use of globally unique identifier values. The nweguid rule allows you to easily create a new globally unique identifier.

The following C # command-line application shows how it's used:

The following command line describes how to use C ++ to create a globally unique identifier:

Using system;

Namespace displayguid {

Class guidexample {

Static void main (string [] ARGs) {generateguid ();

}

Static void generateguid () {console. writeline ("guid:" + system. guid. newguid (). tostring ());

}}}

From: http://www.downcodes.com/info/2009/07/01/20090701-6473.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.