Guid Constructor Examples in C#

Hi Programmers, welcome to new article of c#.net. this article i’ll write the program for Guid Constructor. The GUID stands for Global Unique Identifier. A GUID is a 128-bit integer (16 bytes). It is using whenever we need unique identifier. The Byte array for GUID must be exactly 8 byte long. The string you provide for Guid should be 32 digits with 4 dashes and Guid string should only contain hexadecimal characters.
Let’s see the codes.

Example 1
Example 2
Example 3
Example 4
Example 5

Directly Test below codes into Editor

using System;
namespace ConsoleApp1 {
    class Program {       
        static void Main(string[] args) { 
            string[] str = { "ca861256ed4289cebacd00aa0087b54456",
                         "CA661289-ED47-80CE-BACD-00AA0087B544",
                         "{CA761298-ED87-88CE-BACD-00AA0087B566}",
                         "(CA761298-ED49-77CE-BACD-00AA0057B883)",
                         "{0xCA761298, 0xED72, 0x22CE, {0xBA, 0xCD, 0x00, " +
                               "0xAA, 0x00, 0x57, 0xB2, 0x12}}" };

            foreach (var guidStr in str)
            {
                Guid g1 = new Guid(guidStr);
                Console.WriteLine("Original Value "+ guidStr);
                Console.WriteLine("Guid: "+            g1);
                Console.WriteLine();
            }
        }
    }
}

*********************************

using System;
namespace ConsoleApp2
{
    class Program 
    {
        static void Main(string[] args)  
        {
            var g = new Guid(0xA, 0xB, 0xC,
                  new Byte[] { 0, 1, 2, 3, 4, 5, 6, 7});

            Console.WriteLine("Guid Example : "+g); 
        }
    }
}

Happy Coding…Thanks.

Post Author: adama