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 8679989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:08:03+00:00 2026-06-12T21:08:03+00:00

Please looking in the below codes: new StreamWriter(c:/myText.txt).Write(Some thing…); And, using (var streamWriter =

  • 0

Please looking in the below codes:

new StreamWriter("c:/myText.txt").Write("Some thing...");

And,

using (var streamWriter = new StreamWriter("c:/myText.txt")
{
    streamWriter.Write("Some thing...");
}

The first code creating the file but doesn’t write “Some thing…” in that.
But the second code works as well and write in that.

Why this issue happens? What is the difference?

  • 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-12T21:08:04+00:00Added an answer on June 12, 2026 at 9:08 pm

    The StreamWriter class implements IDisposable which means that it holds a resource that need to be released or it has some clean up code that needs to be run before the object is garbage collected.

    In this case calling Dispose closes the stream, potentially writing the last data to the stream before doing so.

    By coding new StreamWriter("c:/myText.txt").Write("Some thing..."); you don’t retain a reference to the stream and therefore have no way to call Dispose to properly close the stream.

    Remember, the Garbage Collector never calls dispose for you. You must explicitly do so.

    The second block of code uses the using statement which will automatically call Dispose when the block is exited. This is the correct way to write this code.

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

Sidebar

Related Questions

Im looking to dynamically add some content to container after a certain tag,please have
Please if anyone knows the answer, I´m still looking for 3 days and nothing..
Please pardon my ignorance. I'm looking for a point in the right direction. I
I'm looking for an XSD Documentation Generator for .NET. Please, provide any references. Note:
What I am looking may not be readily available. If so please let me
Please i need help, this code below works fine on my localhost, php5.3+ but
**Updated: (See below)**I have been looking around for couple of days and can't find
First off, I am not an AS 400 guy - at all. So please
Looking for some best practices of UI list on iPhone which has item add/modify/delete
I am very new to OData (only started on it yesterday) so please excuse

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.