c# 4.0 -无法将Pascal代码转换为c#

本文关键字:Pascal 代码 转换 | 更新日期: 2023-09-27 17:49:26

我不知道Pascal,这就是我问的原因。也许它创建了文件,写了一些东西有一个Pascal代码

Program WriteFile;
Uses Crt;
Var Dur,ts,tv,n,vers,i : integer;
    X,FileName : String[12];
    f : file of integer;
begin
  ClrScr;
  Write('Variant=');
  Readln(vers);
  Write('Number of works='); 
  Readln(n);
  Str(vers,X);
  FileName:='Shed'+X+'.tab';
  Assign(f,FileName); 
  Rewrite(f);
  For i:=1 to n do
    begin Writeln(i,'-th work:');
    Write('time of beginning=');
    Readln(ts);
    Write('during='); 
    Readln(Dur);
    tv:=ts+Dur;
    Write(f,ts,Dur,tv)
    end;
  Close(f)
end.

c# 4.0 -无法将Pascal代码转换为c#

我想应该是这样的:

static void Main(string[] args)
    {
        Console.Clear(); //unnecessary
        Console.Write("Variant=");
            int vers = Int32.Parse(Console.ReadLine());
        Console.Write("Number of works=");
            int n = Int32.Parse(Console.ReadLine());
        string X = vers.ToString();
        string FileName = "Shed" + X + ".tab";
        //or string FileName = "Shed" + vers.ToString() + ".tab"; //without unnecessary X variable
        System.IO.File.WriteAllText(FileName, string.Empty); //clear file
        System.IO.StreamWriter file = new System.IO.StreamWriter(FileName);
        int ts;
        int dur;
        int tv;
        for (int i = 0; i < n; i++)
        {
            Console.WriteLine(i.ToString() + "-th work:");
            Console.Write("time of beginning=");
            ts = Int32.Parse(Console.ReadLine());
            Console.Write("during=");
            dur = Int32.Parse(Console.ReadLine());
            tv = ts + dur;
            file.WriteLine(ts.ToString() + "'t" + dur.ToString() + "'t" + tv.ToString());
        }
        file.Close();
    }