当我运行时,我只能得到Month.txt
文件的内容,我明白这只是因为我已经将它设置为foreach
中的字符串,但是我无法弄清楚如何添加其他文件到这个以及我得到的所有文件的内容,而不仅仅是本月?foreach读取多个数组
string[] month = System.IO.File.ReadAllLines
(@"E:\project1\input\Month.txt");
string[] 1_AF = System.IO.File.ReadAllLines
(@"E:\project1\input\1_AF.txt");
string[] 1_Rain = System.IO.File.ReadAllLines
(@"E:\project1\input\1_Rain.txt");
string[] 1_Sun = System.IO.File.ReadAllLines
(@"E:\project1\input\1_Sun.txt");
string[] 1_TBig = System.IO.File.ReadAllLines
(@"E:\project1\input\1_TBig.txt");
string[] 1_TSmall = System.IO.File.ReadAllLines
(@"E:\project1\input\1_TSmall.txt");
System.Console.WriteLine("Contents of all files =:");
foreach (string months in month)
{
Console.WriteLine(months + "\t" + 1_AF + "\t" + 1_Rain + "\t" + 1_Sun + "\t" + 1_TBig + "\t" + 1_TSmall);
}
Console.ReadKey();
你必须创建数组列表并添加单个文件的内容放到这个名单,那么你可以申请的foreach为数组 –
你有没有考虑使用'List','Dictionary',或'Tuple'?它们对于像您的情况非常有用。 – Ian