欢迎光临
我们一直在努力

ADO.NET Quiz 之对象序列化-.NET教程,数据库应用

建站超值云服务器,限时71元/月

假设有一下一个实体类。

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

}

}

先决定用xml 序列化把对象的状态dump到一个xml文件。

代码如下:

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();

注意引用 system.runtime.serialization.formatters.dll

问题是:

1。 person类没有加 serilizable 属性,能序列化成功吗?

2。 password 能够被dump 到文件吗?

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » ADO.NET Quiz 之对象序列化-.NET教程,数据库应用
分享到: 更多 (0)

相关推荐

  • 暂无文章