© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
4 replies
Dou

Get the bytes of byte[] as string

Hi, I have a byte[] like
byte[] arr = new byte[] {1,2,3}
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}
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[]")
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Get array of bytes from DLL
C#CC# / help
3y ago
Get the first letters of a string
C#CC# / help
4y ago
❔ How i can get the amount of bytes of an memory address?
C#CC# / help
3y ago
Parsing a string into a Vector of bytes most efficiently
C#CC# / help
4y ago