《21天学通C#》将写的代码原封不动的在控制台显示

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}\n\n", e);
}
Console.WriteLine("请按任意键退出程序!");
Console.ReadKey();
}
}
}

然后打开VS 2017开发人员命令提示符,切换到Program.cs所在目录,输入csc Program.cs

然后再次输入Program Program.cs

如图所示:

会显示出所写代码

posted on 2018-11-05 15:50  天源  阅读(274)  评论(0编辑  收藏  举报

导航