Skip to main content

Posts

Showing posts from January, 2015

polymorphism interview questions and answers in c#

Question: What is polymorphism in c#? Answer: Polymorphism mean one object behaving as multiple forms. One object or function shows different behavior in different scenario is called polymorphism. For example : Dilip is a human object or function which talking behavior will change according his Father, Mother, Son, Boss etc. In C# there are two types of polymorphism 1.  Static or Compile time ·         Function Overloading ·         operator overloading 2.  Run Time ·         Virtual function
Question: What is method overloading ? Answer: When a class have more than one method with same but different signature is called method overloading. For example: using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace ConsoleApplication1 {
classA     {        //1- Passed string parameter publicvoid Add(string a, string b)         {             a = a + b; Console.WriteLine(a);         }        //2- Passed int parameter publicvoid Add(int a, int b)         {             a = a + b; Cons…

Difference between @@IDENTITY, SELECT SCOPE_IDENTITY(), SELECT IDENT_CURRENT

SELECT @@IDENTITY: it’s responsible toreturns the last identity value generated for any table in the current session, across all scopes (i.e. global scope).

SELECT SCOPE_IDENTITY():It’s responsible toreturns the last identity value generated for any table in the current session and the current scope(i.e. local scope). SELECT IDENT_CURRENT(‘table_name’): It’s responsible toreturns the last identity value generated for a specific table in any session and any scope (i.e. global scope). Following example may clear your concept. CREATETABLE TBL1 (id INTIDENTITY(1,1)) CREATETABLE TBL2( id INTIDENTITY(100,1)) GO
CREATETRIGGER TGR ON TBL1 FORINSERT AS BEGIN INSERT TBL2 DEFAULTVALUES END GO
INSERT TBL1 DEFAULTVALUES SELECT@@IDENTITYAS FOR_IDENTITY SELECTSCOPE_IDENTITY()AS FOR_SCOPR_IDENDITY SELECTIDENT_CURRENT('TBL1')AS FOR_IDENT_CURRENT_TBL1 SELECTIDENT_CURRENT('TBL2')AS FOR_IDENT_CURRENT_TBL2 GO DROPTABLE TBL1 DROPTABLE TBL2 GO