OOPS
Can we have shared events ?
Dec 13th
Yes, you can have shared event’s note only shared methods can raise shared events.
Can two catch blocks be executed?
Dec 6th
No, once the proper catch section is executed the control goes finally to block. So there will not be any scenarios in which multiple catch blocks will be executed.
What is Indexer ?
Dec 6th
An indexer is a member that enables an object to be indexed in the same way as an array.
If we write a goto or a return statement in try and catch block will the finally block execute ?
Dec 6th
The code in then finally always run even if there are statements like goto or a return statements.
Can we have different access modifiers on get/set methods of a property ?
Dec 6th
No we can not have different modifiers same property. The access modifier on a property applies to both its get and set accessors.
In what instances you will declare a constructor to be private?
Dec 6th
When we create a private constructor, we can not create object of the class directly from a client. So you will use private constructors when you do not want instances of the class to be created by any external client. Example UTILITY functions in project will have no instance and be used with out creating instance, as creating instances of the class would be waste of memory.
How do I force the Dispose method to be called automatically, as clients can forget to call Dispose method?
Dec 6th
Call the Dispose method in Finalize method and in Dispose method suppress the finalize method using GC.SuppressFinalize. Below is the sample code of the pattern. This is the best way we do clean our unallocated resources and yes not to forget we do not get the hit of running the Garbage collector twice.
Note:- It will suppress the finalize method thus avoiding the two trip. Public Class ClsTesting
Implements IDisposable
Public Overloads Sub Dispose()Implements IDisposable.Dispose ‘ write ytour clean up code here
GC.SuppressFinalize(Me) End Sub
Protected Overrides Sub Finalize() Dispose()
End Sub End Class
What is the use of DISPOSE method?
Dec 6th
Dispose method belongs to IDisposable interface. We had seen in the previous section how bad it can be to override the finalize method for writing the cleaning of unmanaged resources. So if any object wants to release its unmanaged code best is to implement IDisposable and override the Dispose method of IDisposable interface. Now once your class has exposed the Dispose method it’s the responsibility of the client to call the Dispose method to do the cleanup.
