c# using statement and StreamWriter -


i using streamwriter write things notepad. , discover if not using statement , instance streamwriter alone. method unable run. know reason?

    static void main(string[] args)     {         //streamwriter c = new streamwriter(@"c:\users\rxxx\desktop\important.txt", true);         using (streamwriter c = new streamwriter(@"c:\users\xxx\desktop\important.txt", true))         {             c.writeline("hello");         } 

this can run. if run remarked part instead. notepad shows nothing.

anybody knows reason?

because when use object in using practice, calls dispose method , in case of streamwriter call fush on object causes data written in file. write code this:

var c = new streamwriter(@"c:\test\important.txt", true); c.autoflush = true; c.writeline("hello"); c.dispose(); 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -