none
请教全局变量的用法 RRS feed

  • 问题

  • 为什么说我的程序有错呢 是不是全局变量用错了?

     

    namespace ConsoleApplication1

    {

        class Program

        {

            static void Main(string[] args)

            {

                test a = new test();

                string newdate = "20100217", olddate = "20110122";

                public static string[] newDateList = new string[5];

                newDateList = DateList(newdate);

                public static string[] oldDateList = new string[5];

                oldDateList = DateList(olddate); //我想把newDateList、oldDateList设为全局变量,它调用test类里面的DateList函数得到日期的数组。数组值不变。

                a.CopyDirectory("D:\\1", "E:", oldDateList, newDateList);  //CopyDirectory就调用newDateList、oldDateList的值

                 public class test

            {

                public test()

                {

                }

           public string [] DateList(string sDateTime) 

           public void readwriterFile(string FileAddress,string oldDateList,string newDateList)

           public void CopyDirectory(string DirectoryPath, string DirAddress, string []oldDateList,string [] newDateList)

    {            for (int i = 0; i < 5; i++) 

                        {if (inf.Name == oldDateList[i])

     

                               还要调用  readwriterFile(FileAddress,oldDateList[i],newDateList[i]     }

    2011年8月16日 8:34

答案