-3

我正在尝试在方法中声明变量。Unfourantly,无论我试图声明什么类型的变量,我都会收到错误“invalid expression term public”

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();

    }
/********************************************************************************/
4

1 回答 1

4

你不能在 a 中使用访问修饰符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.
于 2013-09-02T17:24:27.187 回答