© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
5 replies
Steadhaven

IDisposable and using keyword?

using (Wolf wolf = new Wolf()) {}

public interface ICarnivore {}

public class Wolf : ICarnivore, IDisposable {
   public void Dispose() {}
}
using (Wolf wolf = new Wolf()) {}

public interface ICarnivore {}

public class Wolf : ICarnivore, IDisposable {
   public void Dispose() {}
}

I am trying to understand
using
using
and
IDisposable
IDisposable
.

It seems that we can attach
IDisposable
IDisposable
to any class, which gives us a method called
Dispose
Dispose
that we have to implement. This dispose method is automatically run and does whatever is specified, whenever we shutdown/remove a class.

And
using
using
is something we use for
IDisposable
IDisposable
classes only it seems. And somehow the
using
using
keyword would then know what to do when we shutdown the class...

1- I can kind of understand IDisposable, but want to know if my explanation is correct
2- What does it mean that a class is shutdown/removed? how can I do this in code?
3- the using keyword (as I tried to explain above) still make almost no sense, and I am even sensing it can be used without
IDisposable
IDisposable


(If needed for other language examples then I know Java/Scala/React a bit, but prefer C# explanation :) )
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Is use of IDisposable, using keyword for a UI wait indicator incorrect?
C#CC# / help
3y ago
Using IDisposable in private field
C#CC# / help
12mo ago
✅ namespace and using keyword in C#
C#CC# / help
10mo ago
IDisposable Constructor Injection
C#CC# / help
12mo ago