readline then move the pointer back?

c#, file-io, readline

Solution

In principle, there is no need to do such a thing. If you want to relate two consecutive lines, just adapt the analysis to this fact (perform the line 1 actions while reading line 2). Sample code:

using (System.IO.StreamReader sr = new System.IO.StreamReader("path"))
{
    string line = null;
    string prevLine = null;
    while ((line = sr.ReadLine()) != null)
    {
        if (prevLine != null)
        {
            //perform all the actions you wish with the previous line now
        }

        prevLine = line;
    }
}

This might be adapted to deal with as many lines as required (a collection of previous lines instead of just `prevLine`).

Problem

Is there a function in the `streamreader` that allows for peek/read the next line to get more information without actually moving the iterator to the next position? The action on the current line depends on the next line, but I want to keep the integrity of using this code block ``` while((Line = sr.ReadLine())!=null) ```

Original source