using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace 第二天课程课后习题
{
class Program
{
static void Main(string[] args)
{
try
{
int ctr = 0;
if(args.Length<=0)
{
Console.WriteLine("Format:ListIT filename");
}
else
{
FileStream f = new FileStream(args[0],FileMode.Open);
try
{
StreamReader t = new StreamReader(f);
string line;
while((line=t.ReadLine())!=null)
{
ctr++;
Console.WriteLine("{0}:{1}", ctr, line);
}
f.Close();
}
finally
{
f.Close();
}
}
}
catch(System.IO.FileNotFoundException)
{
Console.WriteLine("ListIT could not find the file", args[0]);
}
catch(Exception e)
{
Console.WriteLine("Exception:{0}
", e);
}
Console.WriteLine("请按任意键退出程序!");
Console.ReadKey();
}
}
}
然后打开VS 2017开发人员命令提示符,切换到Program.cs所在目录,输入csc Program.cs
然后再次输入Program Program.cs
如图所示:
会显示出所写代码