Sunday, December 10, 2017

The distinction between .Write and .WriteLine at a C# StreamWriter is bigger than you think.

streamWriter.Write("foo");

 
 

...is going to replace everything in a file with merely "foo" while...

streamWriter.WriteLine("bar");

 
 

...is just going to append "bar" on a separate line following everything else. There is another difference however, all lines written with .WriteLine are followed by a carriage return, like it or not, but a carriage return does not chase a write with .Write. You have to append \r\n to what you write with .Write to put it there. Well, that is if you want it to begin with.

No comments:

Post a Comment