我使用 C# .net 4.0 并没有看到任何可能的方法,但也许你知道吗?:)
我以这种方式进行序列化:
public static void SaveCollection<T>(string file_name, T list)
{
BinaryFormatter bf = new BinaryFormatter();
FileStream fs = null;
try
{
fs = new FileStream(Application.StartupPath + "/" + file_name, FileMode.Create);
bf.Serialize(fs, list);
fs.Flush();
fs.Close();
}
catch (Exception exc)
{
if (fs != null)
fs.Close();
string msg = "Unable to save collection {0}\nThe error is {1}";
MessageBox.Show(Form1.ActiveForm, string.Format(msg, file_name, exc.Message));
}
}