Deserialize Object from String - CSharp System

CSharp examples for System:String Encode Decode

Description

Deserialize Object from String

Demo Code


using System.Text;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Web.Security;
using System.Web;
using System.Configuration;
using System.Security.Cryptography;
using System.Data;
using System;// w ww . j  a  v a  2s.c  o  m

public class Main{

    public static object DeserializeObject(string str)
    {

        object obj;

        System.Runtime.Serialization.IFormatter bf = new BinaryFormatter();

        byte[] byt = Convert.FromBase64String(str);

        using (System.IO.MemoryStream ms = new System.IO.MemoryStream(byt, 0, byt.Length))
        {

            obj = bf.Deserialize(ms);

        }

        return obj;

    }
}

Related Tutorials