Mono error: error CS0117: `System.IO.File' does not contain a definition for `ReadLines'
题
I followed this thread to install Mono on my Fedora box:
Install Mono on Centos 5.5 using YUM
However, when I try and compile my program using:
gmcs foo.cs
I get:
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)
Compilation failed: 1 error(s), 0 warnings
The line in question is:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
foreach(int currentMax in File.ReadLines(args[0]).Select(int.Parse))
{
...
}
Can anyone point me in the right direction?
解决方案
So it looks like the problem is that you are using the gmcs
compiler, which is designed specifically for targeting the .Net 2.0 runtime. The list of C# compilers for mono is:
- mcs - .Net 1.1 runtime (deprecated)
- gmcs - .Net 2.0 runtime
- smcs - .Net 2.1 runtime
- dmcs - .Net 4.0 runtime
(see here for more details)
So the compiler you should be using for targeting .Net 4.0 is dmcs
. Instead, if you actually intended to target .Net 2.0, then use the File.ReadAllLines
method that @kil and @minitech talked about.
其他提示
I believe you want File.ReadAllLines
.
不隶属于 StackOverflow