帮忙看下类中的这个错误是什么意思?怎么回事?怎样修改?错误提示信息:
错误 1 “xml_test2.Program.CreateCategoriesByXAttribute()”: 并非所有的代码路径都返回值 C:\Users\Administrator\Desktop\test\xml_test2\xml_test2\Program.cs 49 33 xml_test2代码如下:
public static XElement CreateCategoriesByXAttribute()
{
string path = "../../Test2.xml";
XElement root = new XElement("Categories",
new XElement("Category",
new XAttribute("CategoryID", Guid.NewGuid()),
new XElement("CategoryName", "Beverages")
), new XElement("Category",
new XAttribute("CategoryID", Guid.NewGuid()),
new XElement("CategoryName", "Condiments")
), new XElement("Category",
new XAttribute("CategoryID", Guid.NewGuid()),
new XElement("CategoryName", "Confections")
) );
root.Save(path);
}
错误 1 “xml_test2.Program.CreateCategoriesByXAttribute()”: 并非所有的代码路径都返回值 C:\Users\Administrator\Desktop\test\xml_test2\xml_test2\Program.cs 49 33 xml_test2代码如下:
public static XElement CreateCategoriesByXAttribute()
{
string path = "../../Test2.xml";
XElement root = new XElement("Categories",
new XElement("Category",
new XAttribute("CategoryID", Guid.NewGuid()),
new XElement("CategoryName", "Beverages")
), new XElement("Category",
new XAttribute("CategoryID", Guid.NewGuid()),
new XElement("CategoryName", "Condiments")
), new XElement("Category",
new XAttribute("CategoryID", Guid.NewGuid()),
new XElement("CategoryName", "Confections")
) );
root.Save(path);
}
{
string path = "../../Test2.xml";
XElement root = new XElement("Categories",
new XElement("Category",
new XAttribute("CategoryID", Guid.NewGuid()),
new XElement("CategoryName", "Beverages")
), new XElement("Category",
new XAttribute("CategoryID", Guid.NewGuid()),
new XElement("CategoryName", "Condiments")
), new XElement("Category",
new XAttribute("CategoryID", Guid.NewGuid()),
new XElement("CategoryName", "Confections")
) );
root.Save(path);
}
改为public static void CreateCategoriesByXAttribute()
否则需要用XElement改成void 即可