Если вы хотите просто получить шестнадцатеричное представление, вы можете сделать это за один раз:
// 16069c
string value = Convert.ToString(array[1], 16);
Или
string value = array[1].ToString("x");
Или (дополненная версия: не менее 8
символов)
// 0016069c
string value = array[1].ToString("x8");
Если вы хотите манипулировать с помощью byte
s, попробуйте BitConverter
class
byte[] bytes = BitConverter.GetBytes(array[1]);
string value = string.Concat(bytes.Select(b => b.ToString("x2")));
Ваш код изменен:
using System.Runtime.InteropServices; // For Marshal
...
// Marshal.SizeOf - length in bytes (we don't have int.Length in C#)
StringBuilder hex = new StringBuilder(Marshal.SizeOf(array[1]) * 2);
// BitConverter.GetBytes - byte[] representation
foreach (byte b in BitConverter.GetBytes(array[1]))
hex.AppendFormat("{0:x2}", b);
// You can well get "9c061600" (reversed bytes) instead of "0016069c"
// if BitConverter.IsLittleEndian == true
string value = hex.ToString();