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
Post a Comment