WALTER | Workable Algorithms for Location-aware Transmission, Encryption Response

SequentialGuid..::..NewGuid Method

Creates a new sequential GUID using the IClock UTC time.

Namespace:  Walter
Assembly:  Walter (in Walter.dll)

Syntax


public static Guid NewGuid()

Return Value

A new sequential Guid object.

Examples


Generating a new Sequential guid is quite simple as the bellow samples show. Important however is that one can guarantee the sort or is predictable
C#
// Example of generating a new sequential GUID
   Guid newGuid = SequentialGuid.NewGuid();
  Console.WriteLine(newGuid);
Test demonstrating the expected behavior
[TestMethod]
   public void SortOrderTest()
   {
       // Arrange: create 3 GUIDs
       var first = SequentialGuid.NewGuid();
       var middle = SequentialGuid.NewGuid();
       var last = SequentialGuid.NewGuid();

       // Arrange: generate an array with the wrong order
       var unsorted = new Guid[] { last, first, middle };

       // Arrange: use .NET sorting
       var sorted = unsorted.OrderBy(g => g).ToList();

       // Act
       var result = sorted[0].CompareTo(sorted[^1]);

       // Assert
       Assert.IsTrue(result < 0);
   }