C#C
C#3y ago
Dou

Get the bytes of byte[] as string

Hi, I have a byte[] like
byte[] arr = new byte[] {1,2,3}
is there a way to get those 1,2,3 or even better
new byte[] {1,2,3}
.
For more context, what I'm trying to do is, I'm source generating for Roslyn and adding fields to the source code via a method implemented as
private void AddField(string name, string value, string type = "string")
{
    _fields.Append($"private static {type} {name} = {value}\r\n");
}

I want to call
var arr = new byte[] {1,2,3};
AddField("test", /* somehow inline arr to here */, "byte[]")
Was this page helpful?