GUID V4 - Random-Based Identifier (Recommended)
GUID v4 is the most widely used random-based identifier. Learn about its structure, collision probability, advantages and why it is recommended for general-purpose applications.
Generate GUIDs in C# with Guid.NewGuid() for random values and Guid.CreateVersion7() on .NET 9 or newer when you want timestamp ordering plus randomness.
The built-in Guid.NewGuid() API is the standard way to generate a random GUID in .NET.
using System;
Guid id = Guid.NewGuid();
Console.WriteLine(id);
// Example: d0c5d3e8-4a52-4a65-aada-2b9d88f0d4dc.NET 9 and later can generate a time-ordered GUID directly with Guid.CreateVersion7(). If you target an older runtime, use a library that supports RFC 9562 v7.
using System;
Guid id = Guid.CreateVersion7();
Console.WriteLine(id);
// Example: 0195d9f7-f4f2-7c44-bdb3-6f5de9a1a6f0Guid.NewGuid().Guid.CreateVersion7() is available on .NET 9 and later. Use Guid.NewGuid() for random identifiers everywhere, and use a v7-capable library if you need time-ordered IDs on older runtimes.These articles expand on related concepts, formats and practical considerations.