byte[] to ArrayList?
-
07-07-2019 - |
Question
Could somebody tell me how can I convert byte[] to ArrayList by using C# under Windows Mobile?
Later edit:
this would go like having an ArrayList containing instances of a custom type. This list goes to a database (into a blob) as a byte array (the conversion is done by the database API); What I want is to revert the byte[] to ArrayList;
.NET CF does not provide the BinaryFormatter;
Solution
All arrays inherit off ICollection, so you can just use
ArrayList list = new ArrayList(bytearray);
although I would use the generic List<byte> myself using the same method, as that prevents boxing of each byte value in the array. Although arrays don't staticly inherit off the generic IList for the respective type, the CLR adds relevant implementations to each array instance at runtime (see the Important Note here)
OTHER TIPS
Can't you just do this?
ArrayList list = new ArrayList(byteArray);
ArrayList is untyped, and should only be used for compatibility.
I suggest you use a List<byte>:
var list = new List<byte>(byteArray);
Edit: If the database API does the conversion, shouldn't it provide a way to deserialize? Try using Reflector to find out how it does the conversion.
It seems the CF doesn't support the BinaryFormatter
. Do you control the component that is sending that binary data? Can't you transform the data to Xml in that component? If not take a look at the Compact Formatter