C#.net Interview Questions on Destructors

1) What is a Destructor?
Ans) A Destructor has the same name as the class with a tilde(~) character and is used to destroy an instance of a class.

2) Can a class have more than 1(one) destructor?
Ans) No, a class can have only 1(one) destructor.

3) Can structs in C# have destructors?
Ans) No, structs can have constructors but not destructors, only classes can have destructors.

4) Can you pass parameters to destructors?
Ans) No, you cannot pass parameters to destructors. Hence, you cannot overload destructors.

5) Can you explicitly call a destructor?
Ans) No, you cannot explicitly call a destructor. Destructors are invoked automatically by the garbage collector.


No comments:

Post a Comment