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


Please Help Members By Posting Answers For Below Questions

How to assign Null value to Var?

1065


Why can't we use a static class instead of singleton?

956


Which namespaces are necessary to create a localized application?

1143


What is expression tree in c#?

998


How do you inherit a class into other class in c#?

996


What is an abstract class c#?

969