Converts a byte array to its hexadecimal string representation.

Use BitConverter.ToString() to convert the byte array to a string.
Use string.Replace() to remove dashes in the produced string.

代码片段

public static partial class _30s 
{
  public static string ByteArrayToHex(byte[] bytes) 
  {
    return BitConverter.ToString(bytes).Replace("-", "");
  }
}

使用样例

byte[] data = { 241, 89, 54 };

_30s.ByteArrayToHex(data); // "F15936"