Chapter 21st serialization of data access (in. net4.5)

Source: Internet
Author: User

1. Overview

Transfer data between applications, you need to first convert the data object into a character stream or byte stream form, and then the receiving side will receive and then convert back to the original data object. This is serialization and deserialization.

This chapter describes serialization and deserialization in. NET, the kind of serializer, and configuration objects for serialization.

2. Main content

2.1 Serialization and deserialization

Serialization can only hold data parts of an object and cannot save a method part. You can create a custom data transfer object (DTO) to save only the information that you specify.

The. NET platform provides three types of serialization:

①xmlserializer:

[Serializable] PublicclassPerson { PublicstringFirstName {Get;Set; }  PublicstringLastName {Get;Set; }  PublicintAge {Get;Set; } }xmlserializer Serializer=NewXmlSerializer (typeof(person)); stringXML;using(StringWriter StringWriter =NewStringWriter ()) {Person P=NewPerson {FirstName="John," LastName.="Doe", Age= the     }; Serializer.     Serialize (StringWriter, p); XML=stringwriter.tostring ();}  Console.WriteLine (XML); using(StringReader StringReader =NewStringReader (XML)) {Person P=(person) serializer.     Deserialize (StringReader); Console.WriteLine ("{0} {1} is{2} years old ", P.firstname, P.lastname, p.age); } 

Available attribute:

Not to be continued.

Chapter 21st serialization of data access (in. net4.5)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.