【发布时间】:2015-04-20 17:08:42
【问题描述】:
请帮忙。考虑到我缺乏编程知识,无法解决它。
public static void FileOutput(string path, bool rewrite, List<int> NumberOfWords)
{
StreamWriter OutPath;
try
{
OutPath = new StreamWriter(path, rewrite);
}
catch(IOException e)
{
Console.WriteLine(e.Message);
}
for(int i = 0; i < NumberOfWords; i++)
{
try
{
OutPath.Write(NumberOfWords[i]);
}
catch(IOException e)
{
Console.WriteLine(e.Message);
}
}
OutPath.Close();
}
【问题讨论】:
-
屏幕截图令人不快:(如果您可以实际粘贴代码,那就太好了。
-
您可以在此处粘贴并格式化您的代码,请删除该图像并尝试使用 SO 文本编辑器
-
你到底在问什么?需要更多细节。
-
路径可能无效,检查是否捕获异常。
-
因为它不是在所有条件下都设置的,如果你的 Try 抛出一个异常,它将继续下面的 for 循环,其中 Outpath 将为空。该 for 循环应该在 outpath 分配下的 Try...Catch 语句中。
标签: c# variables static-methods