> When I've finished with a DirectoryEntry object, should I be calling
> .Close() or .Dispose() or both?
[quoted text clipped - 7 lines]
>
> Can anyone shed some light on this, please?
I would suggest you called Close(), internally Close calls Dispose(), but
much better would be to use the 'using' statement like this:
using (DirectoryEntry de = ...)
{
....
} // Here de will automaticlly be disposed of.
Willy.
ssg31415926 - 31 Aug 2005 07:07 GMT
I've not seen this 'using' syntax before but I like the look of it. Is
this specifically for defining the part of your code in which the
object is used or does it have other purposes?
Hi,
Dispose method of DirectoryEntry calls the Close method. Ultimately Dispose
will also remove the DirectoryEntry from the owning container, however the
container will take care of this when it is it self disposed.
In short calling either Close or Dispose will achieve the desired effect of
releasing the underlying unmanaged resource. Personally I go with Close
since it reads better for me.
Hope this helps

Signature
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor
> When I've finished with a DirectoryEntry object, should I be calling
> .Close() or .Dispose() or both?
[quoted text clipped - 7 lines]
>
> Can anyone shed some light on this, please?
ssg31415926 - 31 Aug 2005 07:16 GMT
Could you possibly help me on this "owning container" - what is it and
how is it used? I'm self taught (both C# and OO and probably have big
gaps in my knowlegde) and I haven't come across this before.
Feel free to point me in the direction of some material or a good book
that's beyond the basics. Now that I've done the "Introduction to C#"
- level stuff, I'm not sure where to go (and I have to say that at the
Intro level, Microsoft's own: C# Step by step was pretty readable - I
particularly liked the way it taught you C# in the first half and
ignored Windows Forms/Web Forms stuff until the second half).
SSG
Jon Skeet [C# MVP] - 31 Aug 2005 07:19 GMT
> Dispose method of DirectoryEntry calls the Close method. Ultimately Dispose
> will also remove the DirectoryEntry from the owning container, however the
[quoted text clipped - 3 lines]
> releasing the underlying unmanaged resource. Personally I go with Close
> since it reads better for me.
However, calling Close don't have any built-in language support, so you
need to manually write a try/finally statement. Calling Dispose is as
simple as writing a using statement.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too