How to Convert String to Byte Array?

后端 未结 3 1151
失恋的感觉
失恋的感觉 2021-01-17 08:11

I am getting an error reading:

Cannot implicitly convert type \'String\' to \'Byte[]\'

I think \'byte[]\' is byte array - if it

3条回答
  •  忘掉有多难
    2021-01-17 08:30

        static void Main(string[] args)
        {
            string inputStr = Console.ReadLine();
            byte[] bytes = Encoding.Unicode.GetBytes(inputStr);
            string str = Encoding.Unicode.GetString(bytes);
            Console.WriteLine(inputStr == str); // true
        }
    

提交回复
热议问题