0% found this document useful (0 votes)
15 views2 pages

Q14

Questions of CSharp

Uploaded by

Raj Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

Q14

Questions of CSharp

Uploaded by

Raj Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Q01. How is memory allocated for value types reclaimed?

A. Value types are destroyed and their memory reclaimed when the program exits.
B. Value types are destroyed and their memory reclaimed when they go out of scope.
C. Value types are not destroyed and their memory is not reclaimed unless they are
set to null.
D. None of the above

Q02. You create an object by _____________________.


A. using create operator
B. using the new operator
C. calling constructor
D. all of the above

Q03. The process of destroying an object and returning memory back to the heap is
known as ________.
A. Memory management
B. Resource collection
C. Garbage collection
D. Destruction

Q04. What happens when an object is no longer actively referenced?


A. It is destroyed and the memory that it is using is reclaimed as soon as it goes
out of scope.
B. It resides in memory as long as the program executes.
C. It resides in memory unless you explicitly nullify it.
D. It is destroyed and the memory that it is using is reclaimed by garbage
collection process.

Q05. In many of these cases, writing a destructor is unnecessary. Why?


A. The CLR does not guarantee to call destructor every time an object is destroyed.
B. The CLR will automatically clear up any managed resources that an object uses.
C. The CLR prefers the dispose method to destructor.
D. All of the above.

Q06. When can a destructor prove useful?


A. If an object references an unmanaged resource, either directly or indirectly.
B. If an object has asynchronous methods.
C. If an object has long-running methods.
D. If an object uses database connections.

Q07. Which symbol precedes a destructor in a class?


A. A hash (#)
B. A pipe (|)
C. A tilde (~)
D. A minus (-)

Q08. You can declare a destructor in a value type, such as a struct.


A. True
B. False

Q09. You never declare a destructor with parameters.


A. True
B. False

Q10. The process of destroying an object and returning memory back to the heap is
known as ________.
A. Memory management
B. Resource collection
C. Garbage collection
D. Destruction

Q11. What is a destructor?


A. A destructor is a special method that is called when you call the dispose
method.
B. A destructor is a special method, a little like a constructor, except that the
CLR calls it after the reference to an object has disappeared.
C. A destructor is a protected method that is called by derived classes to
dereference the base class's resources.
D. There is no destructor concept in C#.

Q12. How can you release the resource yourself as quickly as possible?
A. By defining destructors.
B. By creating a disposal method.
C. By overriding the finalize method.
D. None of the above.

Q13. The _______ statement provides a clean mechanism for controlling the lifetimes
of resources.
A. do
B. using
C. switch
D. checked

Q14. How can you call a destructor?


A. By calling the dispose method.
B. Setting object reference to null.
C. By calling GC.Collect method.
D. You can't call a destructor. Only the garbage collector can call a destructor.

Q15. How can you force garbage collection?


A. By calling the dispose method on an object.
B. By setting object reference to null.
C. By calling GC.Collect method.
D. You can't force garbage collection.

Q16. How can you support exception-safe disposal in a class?


A. By writing a constructor in the class.
B. By writing a destructor in the class.
C. By providing a dispose method in the class.
D. By implementing the IDisposable interface.

You might also like