Sunday, July 1, 2012

C# interview questions with answers, Part 3


C# developer interview questions and answers.


What is the difference between Finalize() and Dispose()?


Dispose() is called by as an indication for an object to release any unmanaged resources it has held. 
Finalize() is used for the same purpose as dispose however finalize doesn’t assure the garbage collection of an object. 
Dispose() operates determinalistically due to which it is generally preferred.



What is the difference between Debug.Write and Trace.Write? When should each be used?


Debug.Write: Debug Mode, Release Mode, It used while debuging a project.
Trace.write: Release Mode, It used in Released verion of Applications.



Explain the use of virtual, sealed, override, and abstract.


The virtual keyword enables a class to be overridden. If it has to be prevented from being overridden, then the sealed keyword needs to be used. If the keyword virtual is not used, members of the class can even then be overridden. However, its usage is advised for making the code meaningful.


The override keyword is used to override the virtual method in the base class. Abstract keyword is used to modify a class, method or property declaration. You cannot instantiate an abstract class or make calls to an abstract method directly.


An abstract virtual method means that the definition of the method needs to be given in the derived class.



What benefit do you get from using a Primary Interop Assembly (PIA)?


A primary interop assembly contains type definitions (as metadata) of types implemented with COM. Only a single PIA can exist, which needs to be signed with a strong name by the publisher of the COM type library.
One PIA can wrap multiple versions of the same type library.


A COM type library imported as an assembly can be a PIA only if it has been signed and published by the same publisher.


Therefore, only the publisher of a type library can produce a true PIA, that can be considered as the unit of an official type definition for interoperating with the underlying COM types.



Explain the use of static members with example using C#.NET.


Static members are not associated with a particular instance of any class. 
They need to be qualified with the class name to be called. 
Since they are not associated with object instances, they do not have access to non-static members.
i.e.: "this" cannot be used, which represents the current object instance.





No comments:

Post a Comment