adspace
When do we generally use destructors to release resources?
Answer Posted / Rekha Rai
Destructors in C# should be used when an object owns some unmanaged resources that need to be explicitly freed, such as file handles or network sockets. You can implement a destructor by adding the '~' symbol before the method name in the class declaration.n```csharpnclass MyClass : IDisposable{n ~MyClass() {n Dispose();n }n public void Dispose() {n // Free unmanaged resources heren GC.SuppressFinalize(this);n }n}n```
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers