You have to materialize the sequence to make it run:
IEnumerable<List<int>> F() {
return File.ReadLines("input.txt")
.Select(a => a.Split(' ').Skip(1).Select(int.Parse).ToList())
.Where(a => a.Count >= 2)
.Take(3).OrderBy(a => a.Sum())
.Select(a => { Console.Write(a[0]); return a; })
.ToList();
}
On a related note, it is advised to never cause side-effects in LINQ expressions. If this code is for debugging purposes, then it's fine. But if you plan to leave it for future use, then I'd advise you to remove the Console.Write
from inside the LINQ expression.
The reason why we should not cause side effects in expressions is that most of the LINQ operators are lazy-evaluated. This, in turn, is done to improve performance by only evaluating those elements of the sequence that are effectively requested. Now, if evaluation causes side effects, then these effects could happen several times, should the same lazy sequence be evaluated more than once - and that is probably not what you would ever want to happen.