C
C#15mo 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");
}
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[]")
var arr = new byte[] {1,2,3};
AddField("test", /* somehow inline arr to here */, "byte[]")
3 Replies
phaseshift
phaseshift15mo ago
just call tostring on each byte
Dou
DouOP15mo ago
that... actually makes sense lol thanks
Developful
Developful15mo ago
you could also do string.Join()
Want results from more Discord servers?
Add your server