Infolink

 

Search This Blog

Feb 22, 2014

Overloading and Overriding in C# with real world example

In my early day career in many interviews I asked same question, what is overloading and overriding so decided to write this small article which may help someone. We will see here in detail about the overloading, overriding and then differences between them.

Overloading: is the mechanism to have more than one method with same name but with different signature (parameters). A method can be overloaded on the basis of following properties

  1.     Have different number of parameter
  2.     Having same number of parameters but of different type
  3.     Having same number and type of parameters but in different orders

Feb 6, 2014

Difference between CTE and Temp Table

CTE

  • CTE is  un-materialized/ non-indexable (cannot create indexes on CTE)
  • CTE is logical/disposableView
  • CTE persists only till the very next query
  • CTE cannot have constraints
  • CTE is mostly used for recursion, as CTE can call itself
  • CTE resists in memory
 Example 

By using CTE

    ;With CTE1(Addr, FullName, Age)
    AS
    (
    SELECT Addr.Addr, Emp.FullName, Emp.Age from Address Addr
    INNER JOIN Employee Emp ON Emp.EID = Addr.EID
    )
    SELECT * FROM CTE1 --Using CTE
    WHERE CTE1.Age > 50
    ORDER BY CTE1.FullName

Temp Table

  • Temp table gets stored in temp table
  • Temp table persists till the current connection ends
  • Temp table can be referred in sub procedure
  • Temp table can have constraints,indexes and primary defined
  • Indexes can be implemented in Temp Table
  • Data can be updated in Temp Table
  • Temp Tables are stored in disk
Example
Temp Table

    CREATE TABLE #Temp
    (
    UID int,
    FullName varchar(50),
    Addr varchar(150)
    )
    GO
    insert into #Temp values ( 1, 'Raj','Pune');
    GO
    Select * from #Temp 

Feb 5, 2014

Dynamically Changing Master Pages

Suppose we have two Master pages and we want to change them dynamically.

Let the style sheet are:

  1.     blue.master - set background color to Blue
  2.     green.master - set background color to Green
I have added a page with a dropdownlist which list the master pages as option and in the code behind as drop down list selected index changed event response we saved the user selection in the session and in the Page_PreInit event we changed the master page dynamically.

Feb 4, 2014

AsyncPostBackTrigger vs PostBackTrigger with example

In the <triggers> template in an update panel, there are the options of an AsyncPostBackTrigger or a PostBackTrigger. By default, controls outside of an update panel will trigger a normal synchronous post back. The AsyncPostBackTrigger “wires” up these controls to trigger an asynchronous post back. Conversely, controls declared inside an update panel will trigger an asynchronous call by default. The PostBackTrigger short circuits this, and forces the control to do a synchronous post back. Utilizing a simple “time” example:
Related Posts Plugin for WordPress, Blogger...