When do we generally use destructors to release resources?



When do we generally use destructors to release resources?..

Answer / 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

More C Sharp Interview Questions

Can derived classes have greater accessibility than their base types?

1 Answers  


What is protected internal modifier in C#?

1 Answers   Arigo Infotech,


How do generics work in c#?

1 Answers  


What is the difference between a field and a property in c#?

1 Answers  


Is arraylist faster than linkedlist?

1 Answers  


What is dbcontext c#?

1 Answers  


What is executenonquery c#?

1 Answers  


how can include .netframeworl 2.0 in application setup

1 Answers  


What?s a satellite assembly?

1 Answers  


Is c# good for games?

1 Answers  


Can structs in c# have destructors?

1 Answers  


What is the difference between dynamic type variables and object type variables in c#?

1 Answers  


Categories