Data conversion

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In C#, how do I convert a data (could be any primitive types or user defined
structures such as int, short [] ...) to byte[]? How do I convert it back
assume I know the type in advance?
 
You may be able to cast primitive types :

int i =4;
byte b= (byte)i;

However, structs etc. you will most likely need to use the BinaryFormatter
class to convert a type to a byte array, and back.
Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top