Byte [] in ArrayList?

Can someone tell me how can I convert byte [] to ArrayList using C # under Windows Mobile?

Next edit:

  • it will look like an ArrayList contains instances of a custom type. This list refers to the database (in blob) as a byte array (conversion is performed by the database API); I want to return byte [] in an ArrayList;

  • .NET CF does not provide BinaryFormatter;

+4
source share
4 answers

All arrays inherit ICollection, so you can just use

ArrayList list = new ArrayList(bytearray); 

although I would use a generic <byte> list using the same method that prevents boxing of each byte value in the array. Although arrays do not statically inherit from a common IList for the corresponding type, the CLR adds appropriate implementations to each instance of the array at runtime (see Important note here )

+13
source

Can't you do it?

 ArrayList list = new ArrayList(byteArray); 
+3
source

ArrayList is untyped and should be used for compatibility only.

I suggest you use List <byte>:

 var list = new List<byte>(byteArray); 

Edit: If the database API is converting, should it not provide deserialization? Try using Reflector to find out how it is converted.

+2
source

CF doesn't seem to support BinaryFormatter . Do you control a component that sends this binary data? Can you convert the data in Xml to this component? If you don’t take a look at Compact Formatter

0
source

All Articles