One field of our struct is Guid type. How to generate a valid value for it?
535
votes
11 Answers
89
votes
57
votes
35
votes
29
votes
22
votes
2
votes
There's also ShortGuid - A shorter and url friendly GUID class in C#. It's available as a Nuget. More information here.
PM> Install-Package CSharpVitamins.ShortGuid
Usage:
Guid guid = Guid.NewGuid();
ShortGuid sguid1 = guid; // implicitly cast the guid as a shortguid
Console.WriteLine(sguid1);
Console.WriteLine(sguid1.Guid);
This produces a new guid, uses that guid to create a ShortGuid, and displays the two equivalent values in the console. Results would be something along the lines of:
ShortGuid: FEx1sZbSD0ugmgMAF_RGHw
Guid: b1754c14-d296-4b0f-a09a-030017f4461f
0
votes
-2
votes