// hexstr.cs using System; public class ToHexString { static void Main() { byte[] byteArray = { 0, 1, 2, 10, 11, 12, (byte)'a', (byte)'b'}; Console.WriteLine(BitConverter.ToString(byteArray)); // 出力:00-01-02-0A-0B-0C-61-62 for (int i = 0; i < byteArray.Length; i++) { Console.Write("{0:X2} ", byteArray[i]); } // 出力:00 01 02 0A 0B 0C 61 62 } } // コンパイル方法:csc hexstr.cs