C# 我需要用c序列化一个xml文件#
以下代码应该从XML文件读取并在控制台中显示结果:C# 我需要用c序列化一个xml文件#,c#,xml,serialization,C#,Xml,Serialization,以下代码应该从XML文件读取并在控制台中显示结果: class Program { static void Main(string[] args) { Program introToVCS = new Program(); System.Xml.Serialization.XmlSerializer reader = new System.Xml.Serialization.XmlSerializer(introToVCS.G
class Program
{
static void Main(string[] args)
{
Program introToVCS = new Program();
System.Xml.Serialization.XmlSerializer reader = new
System.Xml.Serialization.XmlSerializer(introToVCS.GetType());
// Read the XML file.
System.IO.StreamReader file =
new System.IO.StreamReader("Customer.xml");
// Deserialize the content of the file into a Program object.
introToVCS = (Program)reader.Deserialize(file);
Console.WriteLine(introToVCS);
Console.ReadLine();
}
}
这应该行得通。使用包含路径的文件名
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Xml;
使用System.Xml.Linq;
命名空间控制台应用程序7
{
班级计划
{
常量字符串文件名=@“c:\temp\test.xml”;
静态void Main(字符串[]参数)
{
XDocument doc=XDocument.Load(文件名);
Console.WriteLine(doc.ToString());
}
}
}
您需要解释错误所在。请发布customer.xml文件。包括文件的路径名。