0

I have a byte array and I want to read this array byte by byte and displayed each byte as integer.

how to do this using C#?

1
  • You're better off writing a single question about what it is you are trying to accomplish rather than making a question for every step you take. Commented Aug 28, 2010 at 4:59

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Yep, it is unnecessary. Console.WriteLine calls .ToString() on it anyway.
1

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#

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.