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();

1 Answer 1


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, 2020 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, 2020 at 19:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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