Which part of a GUID is most worth keeping?

前端 未结 5 865
情话喂你
情话喂你 2020-12-15 23:06

I need to generate a unique ID and was considering Guid.NewGuid to do this, which generates something of the form:

0fe66778-c4a8-4f93-9bda-36622         


        
5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-15 23:37

    You can save space by using a base64 string instead:

    var g = Guid.NewGuid();
    var s = Convert.ToBase64String(g.ToByteArray());
    
    Console.WriteLine(g);
    Console.WriteLine(s);
    

    This will save you 12 characters (8 if you weren't using the hyphens).

提交回复
热议问题