3

我按照这个线程在我的 Fedora 机器上安装了 Mono:

使用 YUM 在 Centos 5.5 上安装 Mono

但是,当我尝试使用以下方法编译我的程序时:

 gmcs foo.cs

我得到:

  foo.cs(11,44): error CS0117: `System.IO.File' does not contain a definition for `ReadLines'
/opt/novell/mono/lib/mono/2.0/mscorlib.dll (Location of the symbol related to previous error)

编译失败:1 个错误,0 个警告

有问题的行是:

 using System;
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;

 foreach(int currentMax in File.ReadLines(args[0]).Select(int.Parse)) 
 {
     ...
 }

谁能指出我正确的方向?

4

2 回答 2

2

所以看起来问题在于您使用的gmcs是专门针对 .Net 2.0 运行时设计的编译器。Mono 的 C# 编译器列表是:

  • mcs - .Net 1.1 运行时(已弃用)
  • gmcs - .Net 2.0 运行时
  • smcs - .Net 2.1 运行时
  • dmcs - .Net 4.0 运行时

(见这里了解更多详情)

因此,您应该用于针对 .Net 4.0 的编译器是dmcs. 相反,如果您确实打算以 .Net 2.0 为目标,请使用File.ReadAllLines@kil 和 @minitech 谈到的方法。

于 2011-12-04T02:47:01.070 回答
0

相信你想要。File.ReadAllLines

于 2011-12-04T01:17:34.970 回答