The globally unique identifier consists of a 128-bit integer, and you can use it to enter any computer that requires 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 identifiers.
TechRepublic's free.NET newsletter, published every Wednesday, features helpful tips and coding examples as it discusses issues such as web serving, ASP.NET, ADO.NET, and Visual Studio .NET. You can subscribe now.
When Windows developers need a unique value, they usually use a globally unique identifier. Microsoft uses the term Globally Unique Identifier to describe a unique number that identifies an entity such as Word text.
A globally unique identifier consists of a 128-bit integer (16 bytes), which you can use to enter any computer that requires a unique identifier or any network that requires a unique identifier. There is a very small chance that this type of identifier will be copied.
This article explains how the .NET Framework can help you create your own globally unique identifier.
Everywhere you will see globally unique identifiers are always operated in a Windows environment. When you peruse the registry in a Windows system, you'll find that globally unique identifiers are widely used to identify applications and more. In HKEY_CLASSES_ROOT, it is even used as an identifier for the application software. http://www.downcodes.com
936DA01F-9ABD-4d9d-80C7-02AF85C822A8 is a typical globally unique identifier format.
Create a Globally Unique Identifier with .NET
Having a Globally Unique Identifier makes it easier to store or retrieve information. Especially when it comes to databases, this feature is even more prominent because globally unique identifiers can help you set up an excellent primary key.
Similarly, SQL Server also 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 on 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 globally unique identifier value types. Additionally, this value type includes methods for working with globally unique identifier values. The NweGUID method allows you to easily create a new globally unique identifier.
Thefollowing
C# command-line application shows how it's used:
using System;
namespace DisplayGUID {
class GuidExample {
static void Main(string[] args) {GenerateGUID();
}
static void GenerateGUID() {Console.WriteLine("GUID: " + System.Guid.NewGuid().ToString());
} } }