score:2

Accepted answer

You could set a flag in TakeUntil that indicates that you are past #define BYE:

bool byeFlag = false;
var p = from line in File.ReadLines(file)
        .SkipWhile(l => l.TrimStart() != ("#define HELLO"))
        .TakeUntil(l =>
        {
            bool ret = byeFlag;
            if (l.TrimStart() == "#define BYE")
            {
                byeFlag = true;
            }
            return ret;
        })
        .ToList()
        select new
        {
            File = file,
            Line = line
        };

But as already mentioned, maybe LINQ is not really the best tool for what you are trying to do. Maybe parsers like ANTLR are better suited for the job?


Related Query

More Query from same tag