Something like String.Join(",", new string[] { "a", "b" });
, but for Guid[]
var guids = new Guid[] { Guid.Empty, Guid.Empty };
var str = /* Magic */
// str = 00000000-0000-0000-0000-000000000000,00000000-0000-0000-0000-000000000000
According to MSDN the method Guid. ToString(string format) returns a string representation of the value of this Guid instance, according to the provided format specifier.
A GUID is a 16-byte (128-bit) number, typically represented by a 32-character hexadecimal string.
An integer uses 32 bits, whereas a GUID is 128 bits - therefore, there's no way to convert a GUID into an integer without losing information, so you can't convert it back. EDIT: you could perhaps store the GUID into a GUIDs table where you assign each a unique integer ID.
All GUIDs must be authored in uppercase. The valid format for a GUID is {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} where X is a hex digit (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F). Note that utilities such as GUIDGEN can generate GUIDs containing lowercase letters.
var str = guids.Select(g => g.ToString())
.Aggregate((working, next) => working + "," + next);
Once your list of Guids starts growing, this method of concatenation is going to cause performance issues. You can modify it to use a StringBuilder:
var str = guids.Select(g => g.ToString())
.Aggregate(new StringBuilder(),
(sb, str) => sb.Append("," + str),
sb => sb.ToString());
Both of those are the complicated LINQ Extension method way of doing things. You could also simply use String.Join:
var str = String.Join(",", guids.Select(g => g.ToString()).ToArray());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With