C# winform 怎么保存一个对象到文本文件中 (和读取) C# winform 怎么保存一个对象到文本文件中 (和读取) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 System.IO.StreamWriterSystem.IO.StreamReader 对象必须是 [Serializable()] [Serializable()] class EntryClass { private string name; public EntryClass() { name = ""; } public EntryClass(string dd) { name = dd; } public string GetName() { return name; } }using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Runtime;using System.IO;namespace EntryClassSerialize{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Read_Click(object sender, EventArgs e) { System.Runtime.Serialization.IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); Stream stream = new FileStream("MyFile.txt", FileMode.Open, FileAccess.Read, FileShare.Read); EntryClass myBlock = (EntryClass)formatter.Deserialize(stream); stream.Close(); this.textBox1.Text = myBlock.GetName(); } private void Save_Click(object sender, EventArgs e) { EntryClass myBlock = new EntryClass(textBox2.Text); System.Runtime.Serialization.IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); Stream stream = new FileStream("MyFile.txt", FileMode.Create, FileAccess.Write, FileShare.None); formatter.Serialize(stream, myBlock); stream.Close(); } }} c#调用vb 的dll,参数类型问题 高分线程锁疑问!~在线等!~ 急。。各位帮帮忙。。 在线等。。。 网上没有资料的。请求高人帮忙 请教简单问题问题!等! c#输出excel时候怎样设置(page设置内的扩大缩小印刷的比例) 谁能给一个VS2005的可以下载的网址啊! 有哪位高手做过插件式开发的没? 这句怎么写呀,求助 .net中的打印问题 找OCX专家 帮忙看看这段XML代码
System.IO.StreamReader
class EntryClass
{
private string name;
public EntryClass()
{
name = ""; }
public EntryClass(string dd)
{
name = dd; }
public string GetName()
{
return name;
} }using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime;
using System.IO;namespace EntryClassSerialize
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Read_Click(object sender, EventArgs e)
{
System.Runtime.Serialization.IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
Stream stream = new FileStream("MyFile.txt", FileMode.Open, FileAccess.Read, FileShare.Read);
EntryClass myBlock = (EntryClass)formatter.Deserialize(stream);
stream.Close();
this.textBox1.Text = myBlock.GetName();
} private void Save_Click(object sender, EventArgs e)
{
EntryClass myBlock = new EntryClass(textBox2.Text);
System.Runtime.Serialization.IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
Stream stream = new FileStream("MyFile.txt", FileMode.Create, FileAccess.Write, FileShare.None);
formatter.Serialize(stream, myBlock);
stream.Close(); }
}
}