MyClass myObject = new MyClass();
myObject.Name = "MyClass";
myObject.Items = new List<string>() {
"Item1",
"Item2",
"Item3",
};
IFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream(@"c:\MyFile.dat", FileMode.Create, FileAccess.Write, FileShare.None);
formatter.Serialize(stream, myObject);
stream.Close();
[Serializable]
public class MyClass
{
public String Name { get; set; }
private List<String> _items = new List<string>();
public List<String> Items
{
get { return this._items; }
set { this._items = value; }
}
}
不知道你说的是不是这个意思:)