在公共方法中声明字符串

时间:2013-09-02 17:22:40

标签: c# asp.net

我试图在方法中声明变量。不好意思,无论我试图宣布什么类型的变量,我都会收到错误“无效表达术语公开”

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

    }
/********************************************************************************/

1 个答案:

答案 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.