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(); } } }