The object serialization of Ado.net Quiz

Source: Internet
Author: User
Tags object serialization serialization
The Ado| object assumes that there is a next entity class.

Using System;
Using System.Xml;
Using System.Xml.Serialization;

Namespace Testperson
{
public class Person
{
public string FullName;

[NonSerialized ()]
public string Password;
public Male sex;

}


public enum Male
{
M
F
}
}

First decide to dump the state of an object into an XML file using XML serialization.

The code is as follows:

Person P=new person ();
P.fullname= "Montaquehou";
p.password= "Test";
P.SEX=MALE.M;


XmlSerializer demoserializer=new XmlSerializer (typeof (person));

FileStream fs=new FileStream ("C:\\test.xml", FileMode.Create, FileAccess.ReadWrite);
Demoserializer.serialize (FS,P);
Fs. Close ();

Note Reference System.Runtime.Serialization.Formatters.dll

The problem is:
1. The person class does not have the Serilizable attribute, can serialization succeed?
2. Can Password be dump to a file?






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.