C# GUID

C# Code Snippets GUID
Share:

About

In this code snippet, we will take a look at GUIDs in C#.

A GUID or a Globally Unique Identifier(also known as a Universally unique identifier)  is an alphanumeric sequence of characters that make up a completely unique identifier(at least in theory). One place GUIDs can be used is with databases to serve as a unique ID.

Let’s look at the code example below to see how to make a GUID.

Code:

using System;
namespace guid
{
    class Program
    {
        static void Main(string[] args)
        {
            //GUID creation.
            Guid GUID = Guid.NewGuid();
            //GUID to string conversion.
            string GUIDString = GUID.ToString();
            Console.WriteLine(GUIDString);
            //GUID in string format to guid conversion.
            Guid backToGUID = Guid.Parse(GUIDString);
            Console.ReadLine();
        }
    }
}

Resulting output:

Share:

Leave a Reply

Your email address will not be published. Required fields are marked *

The following GDPR rules must be read and accepted:
This form collects your name, email and content so that we can keep track of the comments placed on the website. For more info check our privacy policy where you will get more info on where, how and why we store your data.

Advertisment ad adsense adlogger