How to Create GUID in C#

Hi Programmers, welcome to new article of c#.net. this article i’ll write the program for GUID. The GUID stands for Global Unique Identifier. A GUID is a 128-bit integer (16 bytes).
It is using whenever we need unique identifier. GUID is struct type. we are using NewGuid method to initializes a new instance of the GUID structure. Each time when Guid.NewGuid() is run it generates a random unique guid values. It comes under System namespace. Let’s see the codes.

Directly Test Below Codes into Editor.

using System;
namespace ConsoleApp1 
{
    class Program 
    {       
        static void Main(string[] args)   
        {
            Guid g1 = new Guid();
            Console.WriteLine(g1);

            Guid g2 = Guid.NewGuid();
            Console.WriteLine(g2);

            Console.WriteLine(Guid.NewGuid());
        }
    }
}

Happy Coding…Thanks.

Post Author: adama