有没有办法在 C# 中序列化整个数组,例如:
[Serializable()]
public class Data
{
public short Some_Short_Data = new short[100,100];
public string Some_String_Data = new string[100,100];
}
然后写入文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
Data Write_Data = new Data();
XmlSerializer Writer = new XmlSerializer(typeof(Data));
using (FileStream file = File.OpenWrite("Myfile.xml"))
{
Writer.Serialize(file, Write_Data); //Writes data to the file
}
当我尝试这个时,它失败了: XmlSerializer Writer = new XmlSerializer(typeof(Data));
说:“反映类型‘数据’时出现错误”
我对 Stack 和 Xml/Xml 序列化都特别陌生,因此将不胜感激。