我目前对c#编程很新。在stackoverflow上,我发现这种将十六进制数字转换为字节数组的方式,但是由于某些未知原因,当我将其打印到控制台时,我得到类似System.Byte[]
的东西。我怎样才能打印该字节数组的值?c#读取十六进制数并将其转换为字节,然后打印它
public static void Main(string[] args)
{
string hex = "010000015908178fd8000f0fcaf1209a953c006900dd0e0022000e050101f0015001150351220142375308c700000036f10000601a520000000053000069de54000000205500000387570d4a9e50640000006f0001";
byte[] array = null;
array = Enumerable.Range(0, hex.Length) // Converts hex string to byte array or am I worng?
.Where(x => x % 2 == 0)
.Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
.ToArray();
Console.WriteLine(array);
}
你提的问题是过于宽泛。根本不清楚你想如何打印数组的值。一种方法是打印原始的'hex'值。另一种方法是编写一个'foreach'来打印每个值。另一种方法是使用'string.Join()'来生成一个合适的字符串。目前还不清楚是否要以十六进制或十进制打印值。从字面上看,你似乎对如何从数组中打印值感到困惑。见例如标记为重复 –
string.Join为我完美工作。谢谢! – CaL17
重复的https://stackoverflow.com/questions/32694766/how-to-print-array-in-format-1-2-3-4-5-with-string-join-in-c以及https: //stackoverflow.com/questions/37663663/print-array-in-console-gives-system-int32。 –