Friday, August 17, 2012

Method Hiding and Overriding in c#


Method Hiding
a. We do not required to implement the base class method with 'Virtual' keyword.
b. We need to implement the subclass method with 'new' keyword
c. If we use hiding concept, there is no relationship between the base class method and the sub class method. The subclass method just hides the base class method
d. If we create a subclass object with base class reference, the object doesnt know that there is another implementation exist in the subclass for the method


Method Overriding
a. We do required to implement the base class method with 'Virtual' keyword.
b. We need to implement the subclass method with 'override' keyword
c. If we use overrider concept, it indicates that the subclass is having override relationship with the baseclass
d. If we create a subclass object with base class reference, the object takes the implementation exist in the subclass for the method

Below are sample code
a. Having two classes with one is base class and another one is subclass

b. Creating three object with one is for base class, next one is subclass with base class referenced, last one is subclass

c. See the output

Singleton Class/ Singleton Design Pattern


Singleton Class/ Singleton Design Pattern
a.       A class for which only one instance can be created.
b.      Provides global point of access
c.       It has the private constructor, so instance cannot be created.
d.      A singleton class cannot be inherited single the constructor is private

Sunday, August 12, 2012

Response.Redirect Vs Server.Transfer

Response.Redirect() sends a redirection header to the client, and the client itself requests the new page.
Server.Transfer() only stops rendering the current page and starts rendering another one. The client is none the wiser.
That's why Server.Transfer() cannot be used to redirect to pages served by another server.