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#
- .NET calls a UUID a GUID, and
Guid.NewGuid()produces a version 4 value. TheGuidstruct is immutable and value-typed, so it costs no allocation in a model;ToString()takes format specifiers —Dfor the hyphenated default,Nfor 32 characters with no hyphens,Bfor braces andPfor parentheses. - .NET 9 added
Guid.CreateVersion7(), which stamps a Unix millisecond timestamp in the leading 48 bits and fills the rest with random data. That is the one to reach for on a high-insert table: sequential values keep inserts at the right edge of the index instead of scattering them, and the overload taking aDateTimeOffsetlets you control the timestamp explicitly.
How to generate
- Press Generate UUID above to mint a value in this browser — nothing is sent anywhere.
- Copy one value with Copy, or set How many and use Copy all for a fixture list.
- Switch Version if your code needs v7 instead of the v4 default, and turn on Formatting to match your stack's conventions.
Use Cases
- Entity Framework Core keys — a
Guid Idinitialised client-side, so the entity has its ID beforeSaveChanges. - ASP.NET Core trace IDs — pair one per request with
Activity.Current. - SQL Server uniqueidentifier — generate in code, or use
NEWSEQUENTIALID()when the insert is server-side.
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-0036c639cad4Parsing
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
UUID v1 GeneratorUUID v3 GeneratorUUID v4 GeneratorUUID v5 GeneratorUUID v6 GeneratorUUID v7 GeneratorUUID v8 GeneratorBulk UUID GeneratorShort UUID GeneratorUUID ValidatorUUID FormatterJavaScript UUID GeneratorTypeScript UUID GeneratorNode.js UUID GeneratorReact UUID GeneratorPython UUID GeneratorJava UUID GeneratorC# UUID GeneratorGo UUID GeneratorPHP UUID GeneratorRuby UUID GeneratorRust UUID GeneratorKotlin UUID GeneratorSwift UUID GeneratorSQL UUID Generator