M
M
Mistake222021-12-08 21:39:42
C++ / C#
Mistake22, 2021-12-08 21:39:42

How does dispose work in c#?

Hello! I would like to know how the DIspose method of the IDisposable interface works. I decided to make a simple class that implements the interface itself

public class Emploer :  IDisposable
    {
        public string Company { get; set; }

        public Emploer( string company)  { Company = company; }

        public void Dispose()
        {
 
        }
    }

and I can't figure out how this method works. Do I need to explicitly implement the object destruction logic?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-12-08
@Mistake22

Do I need to explicitly implement the object destruction logic?

Yes, but maybe there are no resources in your class that need to be freed in some special way - you don't need this interface.
The memory occupied by your class will be automatically freed by the GC when needed.
IDisposable is only needed when you are using some external resources like files, sockets, mutexes, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question