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

  • Home
  • SEARCH
  • 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 8126809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:17:15+00:00 2026-06-06T07:17:15+00:00

I am wanting to read the text of multiple files into a string using

  • 0

I am wanting to read the text of multiple files into a string using a streamreader, but as of right now, my code has me creating a new streamreader every time I want to read a different file. This works, although when repeated hundreds of times, it seems highly inefficient. I am sure this is a very easy fix, but I am still new to programming, so a bit of knowledge would be much appreciated.

An example of the inefficient code I would like to avoid:

someloop
{

    using (StreamReader sR = new StreamReader(changingfilename))
    {
      textString = sR.ReadToEnd();

    }

}
  • 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-06-06T07:17:19+00:00Added an answer on June 6, 2026 at 7:17 am

    Reading from disk is comparatively very slow. The instantiation of a StreamReader is negligible is comparison. The slow part is ReadToEnd(), not new StreamReader(). Try to avoid reading from disk if your code is too slow.

    Some versions of Visual Studio ship with a profiler which will tell you exactly which methods are spending cpu/clock time of your program

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

Sidebar

Related Questions

I'm wanting to read hex numbers from a text file into an unsigned integer
Using HTML5 File API I am able to read text and XML files without
I'm wanting to get the filepath ie /sites/default/files/myfile.pdf for my file uploads. I'm using
I have an application that imports data read from text files from a directory
Hi there I have to read data from text file into the array in
I'm wanting to create a read only text area in my app which allows
Wanting to integrate aspects of SharePoint into an existing website - rather than integrating
I've been wanting to improve my regex skills for quite some time now and
I'm wanting to update a record in my database which has two values, one
Below i have shared my code in detail. I read documentation and everything about

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.