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.

http://msdn.microsoft.com/en-us/library/system.runtime.serialization.formatters.binary.binaryformatter.aspx

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

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -