我试图在方法中声明变量。不好意思,无论我试图宣布什么类型的变量,我都会收到错误“无效表达术语公开”
public void SerializeToXML(List<amzReport> amzReport)
{
private String 4t4t;
XmlSerializer serializer = new XmlSerializer(typeof(List<amzReport>));
TextWriter textWriter = new StreamWriter(@"C:\movie.xml");
serializer.Serialize(textWriter, amzReport);
textWriter.Close();
}
更新后的代码(错误:“;预期”):
/********************************************************************************/
public void SerializeToXML(List<amzReport> amzReport)
{
String 4t4t;
XmlSerializer serializer = new XmlSerializer(typeof(List<amzReport>));
TextWriter textWriter = new StreamWriter(@"C:\movie.xml");
serializer.Serialize(textWriter, amzReport);
textWriter.Close();
}
/********************************************************************************/
答案 0 :(得分:4)
您无法在method scope
中使用访问修饰符,它应该是这样的:
String t4t = "";//must assign a value if you want to assign it to another var, pass it into a method (commonly saying: use it)
//otherwise no need to assign.