score:14

Accepted answer
File.ReadAllLines(myFile)
    .Select(l => l.Split(' ').Select(int.Parse).ToArray()).ToArray();

Or:

List<int[]> forThoseWhoHave1GigFiles = new List<int[]>();
using(StreamReader reader = File.OpenText(myFile))
{
    while(!reader.EndOfStream)
    {
        string line = reader.ReadLine();
        forThoseWhoHave1GigFiles.Add(line.Split(' ')
            .Select(int.Parse).ToArray());
    }
}
var myArray = forThoseWhoHave1GigFiles.ToArray();

And:

File.ReadLines(myFile)
    .Select(l => l.Split(' ')
    .Select(int.Parse).ToArray())
    .ToArray();

In .Net 4.0 and above.

score:2

Do you mean something like this?

StreamReader sr = new StreamReader("./files/someFile.txt");

      var t1 =
        from line in sr.Lines()
        let items = line.Split(' ')
        where ! line.StartsWith("#")
        select String.Format("{0}{1}{2}",
            items[1],
            items[2],
            items[3]);

Take a look to this web: LINK

score:5

Just to complete Jonathan's answer, here's how you could implement the Lines extension method :

public static class TextReaderExtensions
{
    public static IEnumerable<string> Lines(this TextReader reader)
    {
        string line;
        while((line = reader.ReadLine()) != null) yield return line;
    }
}

Related Articles