How to create Guid value in C#?

CsharpServer Side ProgrammingProgramming

A Globally Unique Identifier or GUID represents a gigantic identification number — a number so large that it is mathematically guaranteed to be unique not only in a single system like a database, but across multiple systems or distributed applications.

The total number of unique keys (3.40282366×1038) is so large that the probability of the same number being generated twice is very small. For an application using 10 billion random GUIDs, the probability of a coincidence is approximately 1 in a quintillion.(1030)

For example, in Retail domain if we want to generate a unique for each transaction so that a customer can use that id to do post sale operations like return, adjustment etc., GUID can be used. GUIDs are most commonly written in text as a sequence of hexadecimal digits like 3F2504E0-4F89-11D3-9A0C-0305E82C3301.

Guid is present in System namespace in C#. It can be created like below.

Guid demoGuid = Guid.NewGuid();


 Live Demo

using System;
namespace DemoApplication{
   class Program{
      static void Main(string[] args){
         Guid demoGuid = Guid.NewGuid();


The output of the above code is

Each time when Guid.NewGuid() is called it will generate a random unique guid.
Published on 04-Aug-2020 07:31:14