如何销毁XmlDocument对象? [英] How to destroy XmlDocument object?

查看:131
本文介绍了如何销毁XmlDocument对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在使用流创建XmlDocument并在其中进行了一些更改XmlDocument并将XmlDocument保存到流本身.

XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(fileStream);

////
////

////  
xmlDocument.Save(fileStream);
//how to dispose the created XmlDocument object.

现在如何销毁XmlDocument对象?

Amal Raj U

Amal Raj U

推荐答案

您不知道.

通常,C#没有破坏对象的方法.垃圾收集器会为您处理.

C#, in general, does not have a way to destroy objects. The garbage collector handles that for you.

例外是实现IDispose接口的类(例如FileStream类),在使用该类时,必须确保完成后调用Dispose()方法.或者,也可以在使用"块中使用这样的项目:

The exception is classes that implement the IDispose interface (such as the FileStream class), where you must ensure you call the Dispose() method when you are done with it. Or, alternatively, use such an item in a 'using' block:

using(FileStream fileStream = new FileStream(filePath, FileMode.Open)
{
   XmlDocument xmlDocument = new XmlDocument();
   xmlDocument.Load(FileStream);
   /// etc...
}


这篇关于如何销毁XmlDocument对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆