开发者

Read byte array byte by byte using C#

开发者 https://www.devze.com 2023-01-13 05:20 出处:网络
I have a byte a开发者_运维百科rray and I want to read this array byte by byte and displayed each byte as integer.

I have a byte a开发者_运维百科rray and I want to read this array byte by byte and displayed each byte as integer.

how to do this using C#?


Given that the array is called bytes:

foreach(var b in bytes)
{
    Console.WriteLine((int)b);
}

Though, in all fairness, the cast to int is probably unnecessary for display purposes.


Some of the C# code I have been writing communicates via TCP/IP with legacy C++ applications. Some codes use a raw packet format where C/C++ structures are passed back and forward.

Example of what the legacy code could look like: Best Practice Mapping a byte array to a structure in C#

0

精彩评论

暂无评论...
验证码 换一张
取 消