Windows Phone VII, XML serialization

Source: Internet
Author: User

DataContractSerializer Object
1      Public class Person2     {3          Public intId {Get;Set; }4          Public stringName {Get;Set; }5          Public intAge {Get;Set; }6          Public CharGender {Get;Set; }7}
Person
1         Private Async voidButton_Click (Objectsender, RoutedEventArgs e)2         {3Person Zhang =NewPerson ();4Zhang. Id =1;5Zhang. Name ="Letter Zhang";6Zhang. Age = -;7Zhang. Gender ='male';8             //XML Serialization Tool9DataContractSerializer serializer =NewDataContractSerializer (Zhang. GetType ());Ten             using(MemoryStream ms =NewMemoryStream ()) One             { A Serializer. WriteObject (MS, Zhang); -Ms. Position =0; -                 //reading data from a stream the                 using(varReader =NewStreamReader (ms)) -                 { -                     varresult =awaitReader. Readtoendasync (); - System.Diagnostics.Debug.WriteLine (result); +                 } -             } +}
XmlSerializer Object
1         Private Async voidButton_Click (Objectsender, RoutedEventArgs e)2         {3Person Zhang =NewPerson ();4Zhang. Id =1;5Zhang. Name ="Letter Zhang";6Zhang. Age = -;7Zhang. Gender ='male';8             varSerializer =NewXmlSerializer (Zhang. GetType ());9             varSettings =NewxmlwritersettingsTen             { OneIndent =true, ANewlinechars ="\ r \ n", -Encoding =Encoding.UTF8, -IndentChars ="    " the             }; -             using(varstream =NewMemoryStream ()) -             { -                 using(XmlWriter writer =XmlWriter.Create (stream, settings)) +                 { - Serializer. Serialize (writer, Zhang); +                 } AStream. Position =0; at                 using(varReader =NewStreamReader (Stream, Encoding.UTF8)) -                 { -                     varresult =awaitReader. Readtoendasync (); - System.Diagnostics.Debug.WriteLine (result); -                 } -             } in}

Windows Phone VII, XML serialization

Related Article

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.