c# - How to convert a Collection to byte array -
i have observablecollection<employee>
how convert byte array[]?
the class employee consists of, - employeeid - dateofjoining - age - salary
the service need pass collection expecting data in byte[].
efficient way convert observablecollection byte[]?
or need loop through collection create byte array?
you can use binary formatter serialize collection.
var employees = new observablecollection<employee>(); using (var stream = new memorystream()) { var formatter = new binaryformatter(); formatter.serialize(stream, employees); var bytearray = new byte[stream.length]; stream.seek(0, seekorigin.begin); stream.read(bytearray, 0, (int)stream.length); // whatever want bytes now.... }
Comments
Post a Comment