Errore mono: errore CS0117: `System.io.file 'non contiene una definizione per` readlines'
Domanda
Ho seguito questo thread per installare mono sulla mia scatola Fedora:
Installa mono su CentOS 5.5 usando Yum
Tuttavia, quando provo a compilare il mio programma usando:
gmcs foo.cs
Ottengo:
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 non riuscita: 1 errore / i, 0 avvisi
La linea in questione è:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
foreach(int currentMax in File.ReadLines(args[0]).Select(int.Parse))
{
...
}
Qualcuno può indicarmi nella giusta direzione?
Soluzione
Quindi sembra che il problema sia che stai usando il gmcs
Compilatore, progettato specificamente per il targeting .NET 2.0 Runtime. L'elenco dei compilatori C# per Mono è:
- MCS - .NET 1.1 Runtime (deprecato)
- GMCS - .NET 2.0 Runtime
- SMCS - .NET 2.1 Runtime
- DMCS - .NET 4.0 Runtime
(vedere qui per ulteriori dettagli)
Quindi il compilatore che dovresti utilizzare per il targeting .NET 4.0 è dmcs
. Invece, se si intende effettivamente indirizzare .NET 2.0, quindi usa il File.ReadAllLines
Metodo di cui hanno parlato @kil e @Minitech.
Altri suggerimenti
Credo che tu voglia File.ReadTuttoLines
.