当我与孩子一起工作时,我不确定如何释放 DirectoryEntry 对象。我需要释放所有孩子然后释放父母还是只释放父母?
例如,
using(DirectoryEntry entry = new DirectoryEntry())
{
foreach (DirectoryEntry childEntry in entry.Children)
{
....
}
}
够了吗?
或者需要额外的代码,例如
using(DirectoryEntry entry = new DirectoryEntry())
{
foreach (DirectoryEntry childEntry in entry.Children)
{
using(childEntry)
{
...
}
}
}
?