1. 程式人生 > >C#在控制檯應用程式中顯示輸出位元組型資料

C#在控制檯應用程式中顯示輸出位元組型資料

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] message = new string[2]{ "你好","hello"} ;
            byte[] data=new byte[message.Length];
            for (int i = 0; i < message.Length; i++)
            {
                data[i]=Convert.ToByte(Convert.ToInt32(message[i]));
            }

            foreach (byte b in data)
            {
                Console.WriteLine(b.ToString("X2")+" ");  //法1
            }

            //Console.WriteLine(BitConverter.ToString(data));//法2
            Console.ReadLine();
                
        }
    }
}