Home      Asp.net          Jobs               Faq
 Here i am posting questions asked in a MNC Interview.

Inheritance, Abstract, Interface


1. We can pass instance of the child class variable to base class instance variable .Similarly we can pass Object of the child class to reference of the

base class.


2. Even the base class and child class having same method. We can compile that code it will shows warning as use new keyword for hiding the method in base class only.


3. In the case of method override Virtual and override keywords for override base class methods with chidclass method



Public class BaseClass



                   Public virtual void add ()


                   Console.WriteLine ("I am in class 1");




          Public class ChildClass: BaseClass


                    Public override void add ()


                   Console.WriteLine ("I am in class 2");


                    Void Main (string [] args)



                1. BaseClass c1=new BaseClass ();

                     ChildClass c2=new ChildClass ();

                   C1=C2; //we can pass refence of child class to base class                             C2=C1 //Error

//we cant pass reference of parent class to child class.

                   c2.add (); //it will execute the class1 add method



                2. BaseClass c1=new ChildClass ();

                   c1.add (); //working fine no errors

                     //class 1 add method will execute

//even we pass class2 object instance to class1 class1 execute only their methods only won’t execute class2 methods.

                   ChildClass c1=new BaseClass ();

C1.add (); //cant implicitly convert type SampleTest.Class1 to SampleTest.Class2







Difference between Interface and Abstract class


Abstract class:

  1. It is class. It contains both concrete methods and abstract methods.
  2. It can’t be insatiable.
  3. We can call concrete methods in abstract methods of abstract class, because we can’t create the instance of the class.
  4. All abstract methods in class must be overridden in inheriting class
  5. Multiple inheritance is not possible.




  1. It is interface. It contains only abstract methods.
  2. No need to override the abstract methods of interface in inheriting class. We should implement abstract methods.
  3. Default Access modifier of All members of Interface is public.
  4. Multiple Inheritances is possible.
  5. It is light weight and serializable.


  1. To allow a class to inherit multiple behaviors from multiple interfaces.
  2. To avoid name ambiguity between the methods of the different classes as was in the use of multiple inheritance in C++.
  3. To combine two or more interfaces such that a class need only implement the combined result. The example code for this is provided as a source file to be downloaded.
  4. To allow Name hiding. Name hiding is the ability to hide an inherited member name from any.




Exception handling: 

Handling runtime errors in .net program



Using System. Exception



Catch (Exception exp)



Custom Exception



throws (new Exception (“Your error message”))


Catch (Exception exp)


Q Differenc between session and  application object


The Session object is very similar to the Application object

The main difference between the two is that,

Session Object:


1.It store client data in server that data is  shared between all the pages of the webapplication.

2.Scope of the session object is limited to  current browser session.

If different users accessing the web application, each will have different session state.


Application Object:


1.It store the data in server that data is shared between all the pages through out the application to all the users

2.scope of the Application Object is to all the users.



Q Copy and Clone


Clone it copies only structure doesn’t copy data.

Copy It copies both structure and data.



Q How can u catch the error message from SP


Create procedure sp_error

@emp varchar (50),

@phone int,

@err varchar(50) output




Insert into emp values (@emp, @phone)

if @@ERROR <> 0


Set @err=”Unable to insert data”

//RAISEERROR (“Unable to insert data”,10)




Set @err=” inserted successfully”






Exec sp_error



Sqlconnection con=new Sqlconnection (“user id=sa; password=; database=pub; data source=user”);

Sqlcommand cmd=new Sqlcommand (“sp_error”);


cmd.Parameters.Add (@emp, SqlDbType.VarChar, 50);

cmd.Parameters [“@err”].Direction= ParameterDirection.Input;


cmd.Parameters [“@emp”].value=””;

cmd.Parameters.Add (@err, SqlDbType.VarChar, 50);


cmd.Parameters [“@err”].Direction= ParameterDirection.Output;


cmd.Parameters.Add (@phone, SqlDbType.Int);

cmd.Parameters [“@err”].Direction= ParameterDirection.Input;


cmd.Parameters [“@phone”]hone"=ameters.Item()lcommand()ub;data source=user.value=””;



con.open ();


cmd.ExecuteNonQuery ();

con.close ();


Q Custom Error messeges


Sp_addmessage procedure, to add a new custom error message to the sysmessages table. You can then refer to that new message's ID number when using RAISERROR


sp_addmessage 55555, 10, 'New error message.'

You could then raise that new error in a procedure like this:

RAISERROR 55555, 10


Q We can Call Sp in trigger


Create trigger t_err on emp

for insert

Declare @err varchar (50)

Exec sp_error srrr,4444,ssss,@err output

Select @err



Q 2+null=2



Q Dataset Vs Data Reader

Points to be consider while choosing between the Dataset and Data Reader objects.

1) Dataset Object has Read/Write access, While Data Reader Object has Read-only access

2) Dataset Object Supports multiple tables from different databases, While Data Reader Object Supports a single table based on a single SQL query of one database

3) Dataset Object works under disconnected mode, While Data Reader Object has connected mode

4) Dataset Object is Bind to multiple controls; While Data Reader Object is Bind to a single control

5) Dataset Object supports forward and backward scanning of data, While Data Reader Object supports Forward-only scanning of data

6) Dataset Object has slower access to data; While Data Reader Object has faster access to data

7) Dataset Object has Greater overhead to enable additional features, While Data Reader Object being Lightweight object with very little overhead

8) Dataset Object is supported by Visual Studio .NET tools, while Data Reader Object Must be manually coded

Q Trigger


A trigger is an object contained within an SQL Server database that is used to execute a batch of SQL code whenever a specific event occurs. As the name suggests, a trigger is “fired” whenever an INSERT, UPDATE, or DELETE SQL command is executed against a specific table.



Q Manifest

Assembly Manifest is a data structure which stores information About Assembly.
The following information is stored in Assembly Manifest

1. Assembly Name
2. Culture
3. Version Number
4. Strong Number Information
5. List of All Files in the Assembly
6. Type Reference
7. Assembly Reference List


Q Metadata

It describes contents in an assembly, classes, interfaces, enums, struts, etc.,

Q Reflection:


Using Reflection we can dynamically invoke the methods.

It is a mechanism to access the metadata information of all .net assemblies.

Namespace: System.Reflection.





Q Server.Transefer and Response. Redirect


Server.Transefer vs Response. Redirect


1. Response.Redirect has roundtrip so it puts load on server.Server.Transefer  

has no roundtrip, it doesn’t put load on server. Here server itself redirect to that page.

2. Cross server redirection is possible with only Response. Redirect.

3. Response.Redirect can redirect html pages also


Q View State


Store the html control information under roundtrip. Its values are stored in html hiddenfileds.


Q Smart Navigation


It prevents the flickering and redrawing when the page is post back.


Q Web.config and Machine.config


Applications settings are stored in configuration file.Web.config file configuration settings are applicable to that web application only. In the case of machine.config file

Configuration settings are applicable to all .net application in server.



<appSettings> <add key=”con” value=””></appSettings>

Namespace System. Configuration


String con=ConfigurationSettings.AppSettings ["con"].ToString ();


Q DataTable


DataTable dt =new DataTable ();

//Dynamically adding row to table
TableRow tRow = new TableRow ();
Table1.Rows.Add (tRow);
//Dynamically adding cells to row
TableCell tCell = new TableCell ();
tRow.Cells.Add (tCell);
 objDT = New System.Data.DataTable("Cart") 
 objDT.Columns.Add("ID", GetType(Integer))
            objDT.Columns("ID").AutoIncrement = True
   objDT.Columns("ID").AutoIncrementSeed = 1
    objDT.Columns.Add("Quantity", GetType(Integer))
    objDT.Columns.Add("Product", GetType(String))     objDT.Columns.Add("Cost", GetType(Decimal))
    Dim objDR As System.Data.DataRow
  ObjDR = objDT.NewRow 
    objDR ("Quantity") = txtQuantity.Text
    objDR ("Product") = ddlProducts.SelectedItem.Text
    objDR ("Cost") = Decimal.Parse (ddlProducts.SelectedItem.Value)
    objDT.Rows.Add (objDR)


Q String and StingBuilder


  1. String is immutable .stringbulider is mutable
  2. Internal state of the string object doesn’t change by its operations, In the case of stringbuilder its value changed by its operations.
  3. Namespace: System. Text,  String Builder

                         System, String


4. For stringbuilder we need to call the constructor to initiate the object



Q Array List and Has Table


1.      Array List: It provides collection similar to an array, but that grows dynamically as the number of elements changed and can store any element of data type.

2.      Has table: It provides collection of key value pair that is organized based on the has code of the key.


Q How to bind data to datagrid using SalDataAdapter and dataset


SqlDataAdapter da=new SqlDataAdapter (“select * from jobs”);

                             DataSet ds=new DataSet ();


                             DataGrid1.DataSource=ds.Tables [0];

                             DataGrid1.DataBind ();

Q How to bind data to datagrid without using SalDataAdapter and dataset


SqlCommand cmd=new SqlCommand ();



                             //cmd.Parameter.add (“@Ename”, SqlDbType.Text, 50);

                             //cmd.Parameter [“@Ename”].Value=””;

                   //cmd.Parameter [“@Ename”].Direction=ParameterDirection.IntputType;

                             cmd.CommandText="select * from jobs";


                             con.Open ();

SqlDataReader dr;



                             DataGrid1.DataBind ();

                             dr.Close ();

                             con.Close ();

Q How to access the particular cell in DataGrid



foreach (DataGridItem di2 in DataGrid1.Items)


                                      if (i==3)


                                                table+=di2.Cells [1].Text +"<br>";




Q DataGrid Paging, Sorting





Sub PageIndexChanged_Click (sender As Object, e As DataGridPageChangedEventArgs)
dtgCusts.CurrentPageIndex = e.NewPageIndex
BindTheData ()
End Sub

  Sub SortCommand_Click (sender As Object, e As DataGridSortCommandEventArgs)
    lblOrderBy.Text = “ORDER BY” & e.SortExpression
    BindTheData ()
  End Sub


Q What is the method used to customize the column

Template column


Q Dynamically adding row to datagrid



DataTable dt=new DataTable ();

                             dt=ds.Tables [0];

                             DataRow drow=dt.NewRow ();

                             drow ["name"] ="";

                             drow ["phone"] ="";

                             drow ["Email"] ="test";

                             dt.Rows.Add (drow);


                             DataGrid1.DataBind ();


Q Binding Data to DataDrid


<asp: DataGrid id="DataGrid1" runat="server" Width="368px" AutoGenerateColumns="False">


<asp: TemplateColumn HeaderText="Name">


<asp: Label id="Label3" runat="server">

<%# DataBinder.Eval (Container.DataItem,"name") %>




<asp:TemplateColumn HeaderText="Phone">


<asp: Label runat="server" ID="Label4">

<%# DataBinder.Eval (Container.DataItem,"phone") %>

</asp: Label>



<asp:TemplateColumn HeaderText="Email">


<asp: Label id="Label5" runat="server">

<%# DataBinder.Eval (Container.DataItem,"email") %>

</asp: Label>

<asp:CheckBox id="ch1" OnCheckedChanged="checkedevent" Text="Check" AutoPostBack="True" Runat="server"></asp:CheckBox>

<asp:CheckBox id="CheckBox1" runat="server" OnCheckedChanged="Checked1" AutoPostBack="True"></asp:CheckBox>



<asp: TextBox id="TextBox1" runat="server"></asp: TextBox>






Q What are the fundamental objects in Ado.net


DataSet and DataReader


Q What is Data adapter


Data Adapter is used to get the data from data store and populate the data into dataset. Data Adapter Objects are connect to one or more objects to dataset object


Method of data adapter

Fill, update


Q How can we force the connection object to close after the data reader is closed


cmd.ExecuteReader (CommandBehaviour.close) 



Q How can we force the data reader to return only the schema of the data store rather then data


cmd.ExecuteReader (CommandBehaviour.SchemaOnly)




Q How can you fine tune the command object when we are accepting a single row



cmd.ExecuteReader (CommandBehaviour.SingleRow)


cmd.ExecuteReader (CommandBehaviour.SingleResult)




Q How can you cancel all the changes done in dataset


ds.RejectChanges ()


Q How can you get the changes done in dataset


ds.HasChanges ();

ds.GetChanges ();

Q Default Session Timeout 

20min.We can create cookies less session. This can be set at web.config





            SqlConnectionString="data source=; Trusted_Connection=yes"






Q Golbal.ascx


Golbal.ascx is used to execute the application level events and settings application level variables


Q Difference between Serverside coding and Client side coding


Server side code execute at server side. Client side code is executed at browser.


Q Which Namespace is used to send mail


Namespace: System.web.mail.

Namespace: System.web.mail.mailmessege

Namespace: System.web.mail.smtpmail


Q ViewState can be enabled and disabled in any of the following ways.


Page Level

Control Level

Application Level

Machine Level

To enable or disable View State in the Page Level, use the following in the Page directive of the ASP.NET page.


<%@ Page EnableViewState ="False True" %>

To enable or disable ViewState in the control level, use the following code

<asp: TextBox id="txtCode" runat="server” EnableViewState="false|true" />

To enable or disable ViewState in the Application Level, use the following code in your web.config files.

<pages enableViewState="false|true" />

To enable or disable ViewState in the Machine Level, use the following code in your machine.config files.

<pages enableViewState="false" ... />



Q ASP.Net page life cycle


Page init: It is occur when first time the page is loaded

Page load: It is occur Subsequent request of the page

Postback: when post back events are faired

Page pre render

Unload Release all events in the page


Q Page Directive

Enable view state can be set in two levels

<% @ Page language=”c#” codebehind=”webform1.aspx.cs” autoeventwireup=”false”






<pages buffer="true"
enableViewState="true" enableSessionState="false"


Q Output Cache Directive

<% @OutputCache Duration=”” VaryByParam=”” VaryByCustom=””  VaryByHeader=”” %>


Q RegisterDirective


<%@ Register tagprefix=”control” tagname=”a” src=”webusercontrol.ascx” %>

<control: a></control: a>




Q Cookies


1) Persistent Cookies.
2) Non Persistent Cookies

Persistent cookies are those which is storing in cookies folder in hard disk.
Non persistent cookies are created on memory, inside the browser process. When we close the browser, that memory region will collect by Operating system, and the cookie will also delete. 1) Persistent Cookies.
2) Non Persistent Cookies

Persistent cookies are those which is storing in cookies folder in hard disk.
A non persistent cookie is created on memory, inside the browser process. When we close the browser, that memory region will collect by Operating system, and the cookie will also delete.


Q Project Architecture

Q Generics

Q Collections

Q Satilite, Shared Assembly

Q Partially class