а проблема то в чем?
| Код | 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; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary;
namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
private void button1_Click(object sender, EventArgs e) { SomeClass sc = new SomeClass(); sc.Str = "asd"; sc.Lst = new ListLst(); sc.Lst.a = new List<string>(); sc.Lst.a.Add("5"); sc.Lst.a.Add("7"); sc.Lst.a.Add("9"); Stream stream = File.Open("test.tst", FileMode.Create); BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(stream, sc); stream.Close(); sc = null; stream = File.Open("test.tst", FileMode.Open); bf = new BinaryFormatter(); sc = (SomeClass)bf.Deserialize(stream); stream.Close(); }
[Serializable] public class SomeClass { public Image Img { get; set; } public String Str { get; set; } public ListLst Lst // список объектов { get; set; } } [Serializable] public class ListLst { public List<string> a { set; get; } }
} }
|
|