Asp.net| Create
The globally unique identifier consists of a 128-bit integer that you can use to enter any computer that needs to enter a unique identifier or any network that requires a unique identifier. Tony Patton explains how the. NET Framework teaches you to create your own globally unique identifier.
TechRepublic's Free.net newsletter is published every Wednesday, in discussions such as Web services, asp.net, ado.net, and Visual Studio. NET, it gives examples of useful hints and encodings. You can subscribe now.
When Windows developers need a unique value, they typically use a globally unique identifier. Microsoft describes a unique number using the term globally unique identifier, which identifies an entity such as word text.
A globally unique identifier consists of a 128-bit integer (16 bytes) that you can use to enter any computer that needs to enter a unique identifier or any network that requires a unique identifier. The likelihood of this type of identifier being replicated is very small.
This article explains how the. NET Framework helps you create your own globally unique identifier.
Wherever you are, you will see that the globally unique identifier always operates in a Windows environment. When you read the registry carefully in the Windows system, you will find that the globally unique identifier is widely used to identify applications and so on. In HKEY_CLASSES_ROOT, it is even used as an identifier for the application software.
936DA01F-9ABD-4D9D-80C7-02AF85C822A8 is a typical format for globally unique identifiers.
Create a globally unique identifier with. Net
Having a globally unique identifier makes it easier to store or retrieve information. This is especially true when it comes to databases, because a globally unique identifier can help you set up a good primary key.
Similarly, SQL Server supports a globally unique identifier that can store a globally unique identifier for a uniqueidentifier data type. You can set an identifier value in SQL Server using the NEWID () feature, or you can set the identifier value in another system and then manually insert the value into SQL Server.
The latter approach is straightforward in. NET. The basic system classes in the. NET Framework include the value types of globally unique identifiers. In addition, this value type includes a method that uses a globally unique identifier value. And the Nweguid rule allows you to easily create a new global unique identifier.
The following C # command-line application shows how it ' s used:
The following command line describes how to create a globally unique identifier in C + +:
Using System;
Namespace Displayguid {
Class Guidexample {
static void Main (string[] args) {generateguid ();
}
static void Generateguid () {Console.WriteLine ("GUID:" + System.Guid.NewGuid (). ToString ());
} } }