怎样用二进制文件方式写入double类型的数
要求:用二进制文件方式写入100个double类型的数,并能够按照指定序号(位置)读取这个数
我现有程序是
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace 二进制文件
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
saveFileDialog1.Filter = "数据类型(*.dat)|*dat|所有文件(*.*)|*.*";
if(saveFileDialog1.ShowDialog()==DialogResult.OK )
{
string Binarysavefilepath=this .saveFileDialog1 .FileName ;
if(File.Exists (Binarysavefilepath))
File .Delete(Binarysavefilepath);
FileStream fs =File .OpenWrite(Binarysavefilepath );
BinaryWriter bw=new BinaryWriter(fs,Encoding .Default );
bw.Write (richTextBox1 .Text );
bw.Close ();
fs.Close ();
MessageBox.Show ("写入文件成功!");
}
}
private void button2_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "数据类型(*.dat)|*dat|所有文件(*.*)|*.*";
if(openFileDialog1.ShowDialog()==DialogResult.OK )
{
string Binaryopenfilepath=this .openFileDialog1 .FileName ;
FileStream fs =File .OpenRead(Binaryopenfilepath );
BinaryReader br=new BinaryReader (fs,Encoding .Default );
richTextBox1.Text = br.ReadString();
br.Close ();
fs.Close ();
}
}
private void button3_Click(object sender, EventArgs e)
{
int location = Convert .ToInt32(textBox1 .Text);
if (openFileDialog1 .ShowDialog () == DialogResult .OK)
{
string path = this .openFileDialog1 .FileName ;
FileStream fs = File .OpenRead (path );
BinaryReader br = new BinaryReader (fs ,Encoding .Default );
fs.Seek(location ,SeekOrigin .Begin);
richTextBox1 .Text = br .ReadChar ().ToString ();
br.Close();
fs.Close ();
}
}
}
}
请问我怎样改才能写入double类型的数