在XmlSerializer構造函數行中,下面的內容會導致一個InvalidOperationException,它也會抱怨沒有爲泛型類型實現默認的accesor。在C#中,如何序列化隊列<>? (.Net 2.0)
Queue<MyData> myDataQueue = new Queue<MyData>();
// Populate the queue here
XmlSerializer mySerializer =
new XmlSerializer(myDataQueue.GetType());
StreamWriter myWriter = new StreamWriter("myData.xml");
mySerializer.Serialize(myWriter, myDataQueue);
myWriter.Close();
你也可以使用queue.ToList() – chakrit 2008-11-21 21:16:15