Is there an equivalent method in C#
to the Java method Arrays.ToString(byte[])
Found here
Essentially I want to convert a byte array to a string of the format:
"[10, 23, 0, 15]"
The numbers reflecting the value of each byte in the byte array.
Is there an equivalent method in C#
to the Java method Arrays.ToString(byte[])
Found here
Essentially I want to convert a byte array to a string of the format:
"[10, 23, 0, 15]"
The numbers reflecting the value of each byte in the byte array.
It's a one-liner. Try this:
static string Array2String<T>( IEnumerable<T> list )
{
return "[" + string.Join(",",list) + "]";
}
You might need to tweak it a bit for different flavors of T
to allow for proper quoting and/or stringification1 etc., but that's the general principle.
1 Not all types have a ToString()
that comes back with anything terribly useful since object
just hands back the type name.