views:

62

answers:

1

I just want to convert a piece of PHP code to C# so I need it's equivalent.

And what does unpack really do? I'm very interested in this function.

+1  A: 

Unpack reads the binary data according to the data type you tell it to parse as and returns the values in an array.

The closest thing I can think to this would be to a struct within C(++) / C#, where it populates the struct's members with information from the binary data. A struct within C style languages is like an object, but without methods.

I can't think of any good examples right now on how to read data into a struct, but that's because I'm not really very good at C or C++ or C# for that matter. Try looking at this for examples on how to read data into structs ... or as always ... google it.

Mark Tomlin
Here's an implementation for C, http://asgaard.homelinux.org/svn/rotekopp/pickle.c , you'd call it like depickle(buf,"SLS",(though only integer support so far)
nos
Thank you for that @nos.
Mark Tomlin
I think using stuct with pointers is a lot easier.
Jonathan Shepherd
I tend to agree with you @Jonathan, but I also think that's due to the fact that its the only way I really handle reading data in to struct. (In the packet based system that I read from.)
Mark Tomlin