.net下二进制序列化
时间:2011-04-23 来源:Y#
c#下的序列化代码如下所示
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace WindowsApplication2 { [Serializable] public class Object5 { public int i1 = 0; public int i2 = 0; public float f3=0; public string str; } private void button1_Click(object sender, System.EventArgs e) { Object5 obj = new Object5(); obj.i1 = 128; obj.i2 = 24; obj.f3=1.3f; obj.str = "Some String"; double d1=1.3d; float f1=1.3f; int i1=1; string s1="HelloWorld"; System.Runtime.Serialization.IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); System.IO.Stream stream = new System.IO.FileStream("File.bin", System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None); formatter.Serialize(stream, obj); formatter.Serialize(stream,d1); formatter.Serialize(stream,f1); formatter.Serialize(stream,i1); formatter.Serialize(stream,s1); stream.Close(); formatter=null; } }
相关阅读 更多 +
- 系统休眠文件删除后果 如何删除计算机的休眠文件 2025-04-22
- 站群服务器是什么意思 站群服务器的作用 站群服务器和普通服务器的区别 2025-04-22
- jQuery插件有何作用 jQuery插件的使用方法 2025-04-22
- jQuery插件有哪些种类 简单的jQuery插件实例 2025-04-22
-