Is it possible to write this method in a prettier way?

public static string ByteArrayToString(byte[] byteArray)
  var hex = new StringBuilder(byteArray.Length * 2);
  foreach (var b in byteArray)
    hex.AppendFormat("{0:x2}", b);
  return hex.ToString();

There are popular topics on StackOverflow that cover this exact question:

  • \$\begingroup\$ It seems that just as on StackOverflow, consensus here is that link-only answers aren't preferable. \$\endgroup\$ May 22 '20 at 18:50
  • \$\begingroup\$ This answer refers to internal stackoverflow links, not external. Basically it says “this question has already been answered”. I don’t see any reason to copy/paste the code from similar answers. \$\endgroup\$
    – almaz
    May 23 '20 at 19:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.