Search This Blog

Saturday, July 9, 2011

Generating a GUID - C#

If you like this article, please click on +1 button and share with your friends.

Click here for the Video Tutorial of this article.

 

GUID stands for Globally Unique IDentifier. It is a string of numbers and/or letters that is unique. It is a unique identifier, that means that as per the claims by Microsoft, this ID whenever you generate, will be unique and its practically impossible to generate the same number again or being duplicated. GUIDs can be used for various purposes. You can use a GUID as a primary key in your database table in case you have many databases scattered around and you would want to sync the records

GUID stands for Globally Unique IDentifier. It is a string of numbers and/or letters that is unique.

It is a unique identifier, that means that as per the claims by Microsoft, this ID whenever you generate, will be unique and its practically impossible to generate the same number again or being duplicated.

GUIDs can be used for various purposes.

  • You can use a GUID as a primary key in your database table in case you have many databases scattered around and you would want to sync the records with each other. In other words, if you have a distributed application with database at each client or center and data is generated and stored in all those locations. But you want to merge all those records at some time interval. In such case, you can use GUID as the primary key. Since its unique, you can be sure of no clashes when you import and sync the records.

    Another use can be that you might want to auto generate a password for all the new users who registers on your site or in case where a user wants to reset his password.

    Practically there are a lot of situations where you might want to use this. But in order to generate it, the code is pretty simple.


       1: System.Guid guid = System.Guid.NewGuid ();
       2: String id = guid.ToString();



    This code simply generates a number something like this:


    “z91c9121-0c17-4d26-a13d-s2340eb678db”



    Cheers!!!



    MicroMind Information Systems
    #4013, K.R. Road, Banashankari II Stage,
    BANGALORE - 560070
    KARNATAKA, INDIA
    Phone: +91 80 26762747



    visit www.iGnani.com

    Technorati Tags: , , , , , , , , , , , , ,
    Blogger Labels: GUID, Video, Tutorial, Microsoft, GUIDs, database, client, data, interval, password, users, System, NewGuid, MicroMind

  • No comments:

    Post a Comment