Read byte array byte by byte using C#
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#
精彩评论