Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6556077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:53:51+00:00 2026-05-25T12:53:51+00:00

Using a StreamReader, if you dispose the underlying stream, I thought you shouldn’t be

  • 0

Using a StreamReader, if you dispose the underlying stream, I thought you shouldn’t be able to read anymore.

That this is true suggests this question, where it’s suggested that you don’t have to dispose the StreamWriter (in their case) if the life of the underlying stream is handled elsewhere.

But that’s not the case. What I did was the following:

I have a file called delme.txt containing the following

abc
def
ghi

The I run this:

    Stream s = File.OpenRead(@"C:\delme.txt");
    StreamReader sr = new StreamReader(s, Encoding.ASCII);

    Console.WriteLine(sr.ReadLine());

    s.Dispose();

    Console.WriteLine(sr.ReadLine());

And the result is:

abc
def

How is this possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:53:52+00:00Added an answer on May 25, 2026 at 12:53 pm

    Your StreamReader already read the next line into its buffer.
    It won’t go back to the source Stream until it runs out of data in its buffer.

    In fact, it would be impossible for it to throw an exception in that case, since there is no idempotent way to find out whether a Stream has been disposed. (There is no IsDisposed property)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have this method: public StreamReader GetResourceStream(string filename) { using (Stream stream =
I'm using the FileStream and StreamReader classes like so: using(FileStream stream = File.Open(filePath,FileMode.Open,FileAccess.Read,FileShare.ReadWrite)) {
I'm having trouble reading a chunked response when using a StreamReader to read the
So I'm using a StreamReader that uses a MemoryStream to write to a StreamWriter
I'm using streamreader now to read a file of people names, it is a
I've a piece of code: using (StreamReader stream = new StreamReader(file.OpenRead(), Encoding)) { char[]
I have rather class using TcpClient that spins of a Thread doing while (!streamReader.EndOfStream)
Classes such as Stream , StreamReader , StreamWriter etc implements IDisposable interface. That means,
im trying to open a file using StreamReader and ive to set a Encoding,
I am writing a web server application in C# and using StreamReader class to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.