UUID in C#

C# UUID Generator

In .NET the type is called System.Guid — same 128 bits, same RFC — and since .NET 9 it can produce version 7 directly.

.NET 9 v7 supportGuid structFormat specifiers

Generated locally with the Web Crypto API — nothing leaves your browser.

Generating UUIDs in C#

How to generate

  1. Press Generate UUID above to mint a value in this browser — nothing is sent anywhere.
  2. Copy one value with Copy, or set How many and use Copy all for a fixture list.
  3. Switch Version if your code needs v7 instead of the v4 default, and turn on Formatting to match your stack's conventions.

Use Cases

How C# UUID Generator Compares

Guid.NewGuid()v4, random — the long-standing default
Guid.CreateVersion7()v7, time-ordered — .NET 9 and later
NEWSEQUENTIALID()SQL Server-side, sequential, only valid as a column default

Code Examples

C# (.NET 9+)
using System;

Guid v4 = Guid.NewGuid();           // UUID v4, random
Guid v7 = Guid.CreateVersion7();    // UUID v7, time-ordered

Console.WriteLine(v4);              // 9f2c7b41-0d3e-4a55-b6c1-8e7d9f0a1b2c
Console.WriteLine(v4.ToString("N")); // no hyphens
Console.WriteLine(v4.ToString("B")); // {with braces}
Console.WriteLine(v7);              // 0198c2f1-6d8a-72e3-b9c7-0036c639cad4
Parsing
if (Guid.TryParse(input, out Guid parsed))
{
    // parsed is a valid GUID
}
else
{
    // reject — never let Guid.Parse throw on user input
}

Frequently Asked Questions

Is a GUID the same as a UUID?
Functionally yes — both are 128-bit identifiers with the same layout, and System.Guid follows RFC 9562. Microsoft uses the name GUID; the two words are interchangeable in .NET code.
How do I generate UUID v7 in C#?
On .NET 9 or later, call Guid.CreateVersion7(). On earlier versions use the UUIDNext package (Uuid.NewSequential()).
Should I use a Guid as a clustered primary key in SQL Server?
A random uniqueidentifier key fragments the clustered index because inserts land all over it. Either use Guid.CreateVersion7() so values increase, or keep a separate int identity column as the clustered key.

Related tools