Answer by Jim Mischel for Overwrite/delete contents of a text file in c# .net
There's no good reason to buffer all that in memory before writing it to the file. It's easier to open the file by calling File.CreateText, and then write each line to it, like this:private void...
View ArticleAnswer by yuvin for Overwrite/delete contents of a text file in c# .net
You have to either reset the StudentInfoHolder class member before the foreach loop, or even better, use a local string variable in combination with String.Format method like this:string...
View ArticleAnswer by glenebob for Overwrite/delete contents of a text file in c# .net
Try something more like the following. It avoids opening the file twice, and string concatenation, which is not a great idea with immutable strings.// This line over-writes the file if it exists, or...
View ArticleOverwrite/delete contents of a text file in c# .net
I'm making a program that writes a list of student objects to a text file and needs to be saved, I could either simply overwrite the contents of the file or delete the contents and rewrite the new...
View Article