tags:

views:

134

answers:

1

I'm looking for a C# equivalent to the Java's unread() method.

The C# equivalent to PushbackReader is supposedly System.IO.StreamReader, but StreamReader doesnt have an "unread()" equivalent. It has Peek(), but no way to put a character back onto the stream.

Java Code:

// putBackChar puts the character back onto the stream
// adjusts current line number if necessary
private void putBackChar()
{
    if (ch == '\n')
        currentLine--;

    try
    {
        in.unread((int) ch);
    }
    catch (IOException e)
    {}
}
+1  A: 

Peek reads the character without popping it out of the stream so you wouldn't need to put it back onto the stream.

Andrew Hare
Yeah, that'd work. I cant really think of any other reason to push back. I'll stick with Peek(), thanks.
Shane Cusson
Not a problem - good luck!
Andrew Hare