Globally Unique Identifier

Posted: April 18, 2010 in C#, Programming
Tags: ,
A globally unique identifier or GUID is a special type of identifier used in software applications to provide a unique reference number. The value is represented as a 32 character hexadecimal character string, such as {ff478f2d-e398-449a-93d4-62b0727} and usually stored as a 128 bit integer.
The primary purpose of the GUID is to have a totally unique number. Ideally, a GUID will never be generated twice by any computer or group of computers in existence. The total number of unique keys (2^128) is so large that the probability of the same number being generated twice is extremely small, and certain techniques have been developed to help ensure that numbers are not duplicated.
GUIDs have a variety of applications. You can use a GUID as a primary key in your database table or in a several other scenarios. A good example would be, if you have a distributed application where data is generated and stored in various locations and you want to merge all those data at some intervals of time, you may use GUID as the primary key.

GUIDs can be generated in a number of ways; most often a hash of several things that might be unique at any given point in time like the IP address plus the clock date/time etc are used to generate Unique Ids. Each system may have slightly different algorithm to generate the Unique Id.

Here’s how to generate GUID in C# code :

using System;

namespace TestGuid
	class MainClass
		static void Main(string[] args)
			System.Guid guid=System.Guid.NewGuid();

Note : Some content of this article was taken from here


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s