ZengCode.Com (The Thai Php Framework)  


Home   Download   Manual   About us    

Facebook   


MAIN MENU
เขียนโปรแกรมบน iPhone ด้วย MonoTouch
News
Php Tips
Ubuntu
Spring+Strut+Hibernate
Android Programming
Design Pattern By PHP
C# Design Pattern
Linux Quick Tips
C# Tips & Technique
C# using Linq น่าใช้จริงๆ
Java & JavaScript Tips
MAVEN
Database & SQL
ZengCode Framework Guide
Mac OSx
Zeng Code Code
Programming
IPhone (Tips and Trick)

Download เอกสารที่น่าสนใจ

     Object Serialization in C#  (2010-08-17)

ตัวอย่างง่ายๆนะครับ เข้าใจได้ไม่ยาก

 using System.Runtime.Serialization;

[Serializable()]

    public class Employee : ISerializable //derive your class from ISerializable
    {
        public int EmpId;
        public string EmpName;

        //Default constructor

        public Employee()
        {
            EmpId = 0;
            EmpName = null;
        }
        //Deserialization constructor.

        public Employee(SerializationInfo info, StreamingContext ctxt)
        {
            //Get the values from info and assign them to the appropriate properties

            EmpId = (int)info.GetValue("EmployeeId", typeof(int));
            EmpName = (String)info.GetValue("EmployeeName", typeof(string));
        }

        //Serialization function.

        public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
        {
            //You can use any custom name for your name-value pair. But make sure you

            // read the values with the same name. For ex:- If you write EmpId as "EmployeeId"

            // then you should read the same with "EmployeeId"

            info.AddValue("EmployeeId", EmpId);
            info.AddValue("EmployeeName", EmpName);
        }

    }

 ดูตัวอย่างเต็มๆ ที่ http://www.codeproject.com/KB/cs/objserial.aspx


Comment
Name
Comment
Security CodeCAPTCHA Image

web hit counter

This page took 0.052226 seconds to load.