With .NET 4.0, I sometimes have a Guid[] or 200 items that all need conversion to string[], and sometimes I have to do the reverse.
What is the fastest/smartest way to do that?
Thanks.
With .NET 4.0, I sometimes have a Guid[] or 200 items that all need conversion to string[], and sometimes I have to do the reverse.
What is the fastest/smartest way to do that?
Thanks.
An alternative to LINQ is Array.ConvertAll() in this case:
Guid[] guidArray = new Guid[100]; ... string[] stringArray = Array.ConvertAll(guidArray, x => x.ToString()); guidArray = Array.ConvertAll(stringArray, x => Guid.Parse(x)); Runtime performance is probably the same as LINQ, although it is probably a tiny bit faster since it's going from and to array directly instead of an enumeration first.
See if it helps:
Guid[] guids = new Guid[200]; var guidStrings = guids.Select(g => g.ToString()); var revertedGuids = guidStrings.Select(g => Guid.Parse(g));