C#中除了字节类型以外,还有许多其它基本数据类型,例如,int 、bool、float 等等,
读写这些基本数据类型需要使用BinaryReader 和BinaryWriter 类。写int 类型数据代码段如
下:
System.IO.FileStream fs=new System.IO.FileStream("g1",FileMode.OpenOrCreate);
System.IO.BinaryWrite w=new System.IO. BinaryWrite(fs);
For(int i=0;i<10;i++)
w.Write(i);
w.Close();
读int 类型数据代码段如下:
int [] data=new int[10];
System.IO.FileStream fs=new System.IO.FileStream("g1",FileMode.OpenOrCreate);
System.IO.BinaryReader r=new System.IO. BinaryReader(fs);
For(int i=0;i<10;i++)
data[i]=r.ReadInt();
r.Close();
用BinaryReader 和BinaryWriter 类读写基本数据类
最新推荐文章于 2025-06-29 09:42:19 发布
本文介绍了C#中除字节类型外的基本数据类型,并通过实例展示了如何使用BinaryReader和BinaryWrite类进行数据的读写操作。
1123

被折叠的 条评论
为什么被折叠?



