Deserialize an ArrayList object from a SOAP file : ArrayList Serialization : Data Structure C# Examples


C# Examples » Data Structure » ArrayList Serialization »

 

Deserialize an ArrayList object from a SOAP file









    
using  System;
using  System.IO;
using  System.Collections;
using  System.Runtime.Serialization.Formatters.Soap;
using  System.Runtime.Serialization.Formatters.Binary;

class  MainClass
{
        public  static  void  Main()
        {
                ArrayList  people  =  new  ArrayList();
                people.Add("G");
                people.Add("L");
                people.Add("A");

                SoapSerialize(people);
                ArrayList  soapPeople  =  SoapDeserialize();


                Console.WriteLine("\nSOAP  people:");
                foreach  (string  s  in  soapPeople)
                {
                        Console.WriteLine("\t"  +  s);
                }

        }
        //  Serialize  an  ArrayList  object  to  a  SOAP  file.
        private  static  void  SoapSerialize(ArrayList  list)
        {
                using  (FileStream  str  =  File.Create("people.soap"))
                {
                        SoapFormatter  sf  =  new  SoapFormatter();
                        sf.Serialize(str,  list);
                }
        }

        
        private  static  ArrayList  SoapDeserialize()
        {
                ArrayList  people  =  null;

                using  (FileStream  str  =  File.OpenRead("people.soap"))
                {
                        SoapFormatter  sf  =  new  SoapFormatter();
                        people  =  (ArrayList)sf.Deserialize(str);
                }
                return  people;
        }

}
    
   
  
   



Output

SOAP people:
        G
        L
        A


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Structure
» ArrayList Serialization