Skip to content

Instantly share code, notes, and snippets.

@renatogroffe
Created December 2, 2024 14:07
Show Gist options
  • Save renatogroffe/988b6563dc91127be019cf964f12d8cd to your computer and use it in GitHub Desktop.
Save renatogroffe/988b6563dc91127be019cf964f12d8cd to your computer and use it in GitHub Desktop.
using System.Runtime.InteropServices;
using System.Text.Json;
Console.WriteLine("***** Testes com .NET 9 | GUIDs UUID Version 7 *****");
Console.WriteLine($"Versao do .NET em uso: {RuntimeInformation
.FrameworkDescription} - Ambiente: {Environment.MachineName} - Kernel: {Environment
.OSVersion.VersionString}");
List<Guid> guidsV4 = new();
for (int i = 1; i <= 5; i++)
{
var guid = Guid.NewGuid();
guidsV4.Add(guid);
Console.WriteLine($"{guid} - versao {guid.Version}");
Thread.Sleep(1000);
}
Console.WriteLine();
Console.WriteLine($"Guids V4: {JsonSerializer.Serialize(guidsV4)}");
Console.WriteLine();
Console.WriteLine($"Guids V4 - Order(): {JsonSerializer.Serialize(guidsV4.Order())}");
Console.WriteLine();
List<Guid> guidsV7 = new();
for (int i = 1; i <= 5; i++)
{
var guid = Guid.CreateVersion7();
guidsV7.Add(guid);
Console.WriteLine($"{guid} - versao {guid.Version}");
Thread.Sleep(1000);
}
Console.WriteLine();
Console.WriteLine($"Guids V7: {JsonSerializer.Serialize(guidsV7)}");
Console.WriteLine();
Console.WriteLine($"Guids V7 - Order(): {JsonSerializer.Serialize(guidsV7.Order())}");
Console.WriteLine();
List<Guid> guidsV7Utc = new();
for (int i = 1; i <= 5; i++)
{
var guid = Guid.CreateVersion7(DateTimeOffset.UtcNow);
guidsV7Utc.Add(guid);
Console.WriteLine($"{guid} - versao {guid.Version}");
Thread.Sleep(1000);
}
Console.WriteLine();
Console.WriteLine($"Guids V7 UTC: {JsonSerializer.Serialize(guidsV7Utc)}");
Console.WriteLine();
Console.WriteLine($"Guids V7 UTC - Order(): {JsonSerializer.Serialize(guidsV7Utc.Order())}");
Console.WriteLine();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment