Is there a way I can alter this function which converts byte arrays to a string so it doesn’t use LINQ? (to make it compatible with prior .NET versions)?
private string ByteToString(byte[] data)
{
return String.Concat(data.Select(b => b.ToString("x2")));
}
Most methods found on the web, seem to return an unprintable unicode string. The code above above returns a safe string (eg b8b30dcfcac41ebd5313107adf7054024fb1ac69 rather than loads of high-ASCII chars) however I don’t really understand what the function above is doing (especially with regards to the “x2” parameter.
Sure, you can just roll it into a
foreachloop if all you want to do is make the code above “non-LINQ”.String.Concat()just concatenates anIEnumerableinto a string, which we can do with aStringBuilder:Probably many ways to do this, but this would be a fairly literal translation of the LINQ code you list.