如何制作可序列化的文件 [英] How to Make a Serializable File

查看:55
本文介绍了如何制作可序列化的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!



我是一名正在开发桌面应用程序的新手程序员。



你能帮我制作一个可序列化的文件,可以包含在我的应用程序中,其中包含计算机详细信息,如ComputerId,ProcessorId,制造商等,以及应用程序使用的持续时间。



谢谢......

解决方案



使用System.Runtime.Serialization;



使用System.Runtime.Serialization.Formatters.Binary;



FileStream fs = new FileStream(@C:\ ABC.txt,FileMode.Create);



binfor = new BinaryFormatter();



binfor .Serialize(fs,DATATOSERIALIZE);



fs.Close();



和XML序列化



使用System.Runtime.Serialization;



使用System.Runtime.Serialization.Formatters.Soap;



fs =新FileStream(@C:\ ABC.xml,FileMode.Create);



soafor = new SoapFormatter( );



soafor.Serialize(fs,DATATOSERIALIZE);



fs.Close();

Hi to all!

I am a novice programmer which is developing desktop applications.

Can you help me make a serializable file that can be included in my application which contains the computer details such as ComputerId, ProcessorId, Manufacturer, and etc. and also the duration of the application usage.

Thank you ...

解决方案

Hi,
using System.Runtime.Serialization;

using System.Runtime.Serialization.Formatters.Binary;

FileStream fs = new FileStream(@"C:\ABC.txt", FileMode.Create);

binfor = new BinaryFormatter();

binfor.Serialize(fs, DATATOSERIALIZE);

fs.Close();

And For XML Serialization

using System.Runtime.Serialization;

using System.Runtime.Serialization.Formatters.Soap;

fs = new FileStream(@"C:\ABC.xml", FileMode.Create);

soafor = new SoapFormatter();

soafor.Serialize(fs, DATATOSERIALIZE);

fs.Close();


这篇关于如何制作可序列化的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆