When to dispose and why?
问题 I asked a question about this method: // Save an object out to the disk public static void SerializeObject<T>(this T toSerialize, String filename) { XmlSerializer xmlSerializer = new XmlSerializer(toSerialize.GetType()); TextWriter textWriter = new StreamWriter(filename); xmlSerializer.Serialize(textWriter, toSerialize); textWriter.Close(); } in the response I got this as an added remark: Make sure you always dispose disposable resources such as streams and text readers and writers. This