Object To Byte Array To Self - CSharp System

CSharp examples for System:Byte Array

Description

Object To Byte Array To Self

Demo Code


using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO.Compression;
using System.IO;//from   ww  w .jav a 2  s.c  o  m
using System.Data;
using System;

public class Main{
        private static byte[] ObjectToByteArrayToSelf(object o)
        {
            MemoryStream stream = new MemoryStream();
            new DataContractSerializer(o.GetType()).WriteObject(stream, o);
            byte[] buffer = stream.ToArray();
            stream.Close();
            return buffer;
        }
}

Related Tutorials