What happens if StreamReader or StreamWriter are not closed?
问题 I'm working on an assignment for a professor that is strict about LOC. For this reason I'd like to do the following: (new StreamWriter(saveFileDialog.FileName)).Write(textBox.Text); instead of StreamWriter sw = new StreamWriter(saveFileDialog.FileName); sw.Write(textBox.Text); sw.Close(); In the first example I don't close the stream. Is this ok? Will it cause any security or memory problems? 回答1: You may not get any output, or incomplete output. Closing the writer also flushes it. Rather