Dot Net Interview questions for 3+ years of experience - Part-4


Previous questions


1) In Singleton Design Pattern, synchronization is essential ?
Ans) In Singleton Design Pattern , synchronization is essential only for the first time when the instance is to be created. When the instance is created then it becomes an overhead for each request.

public class Singleton

{

private static Singleton uniqueinstance;



private Singleton()

{

}
public static Singleton getinstance()

{

if(uniqueinstance == null)

{

uniqueinstance = new Singleton();

}

return uniqueinstance;

}

}


In the above code, when for the first time getinstance method is called, synchronization is needed. After the first instance is created, we no longer need synchronization.
---------------------------------------------------
2) Tell me the exact difference between IQueryable and IEnumerable interface ?
Ans)
IEnumerable is applicable for in-memory data querying, and in contrast IQueryable allows remote execution, like web service or database querying.
---------------------------------------------------------
3)When a dynamic compilation of a website project is bad ?
Ans)
Dynamic compilation happens for a website project not for a web application project.
If the site is very large, dynamic compilation of a Web site project might take a noticeable amount of time. Dynamic compilation occurs when a request for a site resource is received after an update to the site, and the request that triggers compilation might be delayed while the required resources are compiled. If the delay is unacceptable, you can pre-compile the site. However, then some of the advantages of dynamic compilation are lost.


Previous questions

Previous questions


1) In Singleton Design Pattern, synchronization is essential ?
Ans) In Singleton Design Pattern , synchronization is essential only for the first time when the instance is to be created. When the instance is created then it becomes an overhead for each request.

public class Singleton

{

private static Singleton uniqueinstance;



private Singleton()

{

}
public static Singleton getinstance()

{

if(uniqueinstance == null)

{

uniqueinstance = new Singleton();

}

return uniqueinstance;

}

}


In the above code, when for the first time getinstance method is called, synchronization is needed. After the first instance is created, we no longer need synchronization.
---------------------------------------------------
2) Tell me the exact difference between IQueryable and IEnumerable interface ?
Ans)
IEnumerable is applicable for in-memory data querying, and in contrast IQueryable allows remote execution, like web service or database querying.
---------------------------------------------------------
3)When a dynamic compilation of a website project is bad ?
Ans)
Dynamic compilation happens for a website project not for a web application project.
If the site is very large, dynamic compilation of a Web site project might take a noticeable amount of time. Dynamic compilation occurs when a request for a site resource is received after an update to the site, and the request that triggers compilation might be delayed while the required resources are compiled. If the delay is unacceptable, you can pre-compile the site. However, then some of the advantages of dynamic compilation are lost.


Previous questions

IIS level Questinos , Application server

Q1) What is scavenging ?
Ans)
When server running your ASP.NET application runs low on memory resources, items
are removed from cache depending on cache item priority. Cache item priority is set when you add item to cache. By setting the cache item priority controls the items scavenging are removed first.
Q1) What is scavenging ?
Ans)
When server running your ASP.NET application runs low on memory resources, items
are removed from cache depending on cache item priority. Cache item priority is set when you add item to cache. By setting the cache item priority controls the items scavenging are removed first.

Sql Server Experience Questions

Q1) What is MERGE statement?
Ans)
MERGE is new feature in SQL Server 2008 that provide an efficient way to perform multiple operations. In previous version we had to write separate statement to INSERT,DELETE and UPDATE data based on certain conditions, but now using MERGE statement we can include the logic of such data modification in one statement that even checks when the data matched then just update it and when unmatched then insert it. most important advantage of MERGE statement is all the data is read and processed only once.
---------------------
Q2)What is BCP ?
Ans)
BCP is stand for Bulk copy Program in sql server, bulk copy is a tool used to copy huge amount of data from tables and views. BCP does not copy the structure same as source to destination.
Q1) What is MERGE statement?
Ans)
MERGE is new feature in SQL Server 2008 that provide an efficient way to perform multiple operations. In previous version we had to write separate statement to INSERT,DELETE and UPDATE data based on certain conditions, but now using MERGE statement we can include the logic of such data modification in one statement that even checks when the data matched then just update it and when unmatched then insert it. most important advantage of MERGE statement is all the data is read and processed only once.
---------------------
Q2)What is BCP ?
Ans)
BCP is stand for Bulk copy Program in sql server, bulk copy is a tool used to copy huge amount of data from tables and views. BCP does not copy the structure same as source to destination.

Interview Questions for freshers part -3



Q1)What are User Controls and Custom controls?
Ans)

Custom controls are control build entirely in code. The pro is that you can put them in libraries, add an icon to the toolbox and other fine control.

User controls are more easy to do, and in general is a way to encapsulate things to simplify other pages or when you need to use the same markup in several pages.
--------------------------------------------------------------
Q2)web.config file main two advantages are :-
(1) web.config file cannot be viewed directly in a browser
(2) If the web.config file is changed, you don’t need to re-compile your ASP.NET application

Ans)
Select from following answers:
False
True
Both
Both the above statements are correct.
------------------------------------------------------




Q1)What are User Controls and Custom controls?
Ans)

Custom controls are control build entirely in code. The pro is that you can put them in libraries, add an icon to the toolbox and other fine control.

User controls are more easy to do, and in general is a way to encapsulate things to simplify other pages or when you need to use the same markup in several pages.
--------------------------------------------------------------
Q2)web.config file main two advantages are :-
(1) web.config file cannot be viewed directly in a browser
(2) If the web.config file is changed, you don’t need to re-compile your ASP.NET application

Ans)
Select from following answers:
False
True
Both
Both the above statements are correct.
------------------------------------------------------


Interview Questions for freshers part -2


Q1)difference between array and stack
Ans)
There are two main differences between an array and a stack. Firstly, an array can be multi-dimensional, while a stack is strictly one-dimensional. Secondly, an array allows direct access to any of its elements, whereas with a stack, only the 'top' element is directly accessible; to access other elements of a stack, you must go through them in order, until you get to the one you want
------------------------------------------
Q2)Suppose you have a DataTable having 100,000 rows and 50 columns. Now you've create array of perticular column values, how will you do that?
Ans)
It's simple.
for C#
object[] arr = Array.ConvertAll(dataTable.Select(), (DataRow r) => r[]);
for VB
dim arr as Object() = Array.ConvertAll(Of DataRow, Object)(dataTable.Select(), Function(r as DataRow) r());
------------------------------------------------------------
Q3)Can we assign values to read only variables?if yes then how?
Ans)
yes, we can assign values to read only variables either at a time of declaration or in constructors
-------------------------------------------------------------------
4)Difference between Abstract class and interface?
Ans)
1.Through the abstract class we cannot achieve the multiple inheritance in c-sharp. while by interface we can.
2. We can declare the access modifier in abstract class but not in interface. Because by default everything in interface is public
-----------------------------------------------------------------------
5)You can derive an abstract class from another abstract class. In that case, in the child class it is optional to make the implementation of the abstract methods of the parent class....!
Ans)
Select from following answers:
True
False
No Idea
True
If the derived class is also an abstract class then it is not mandatory to implement the abstract method of the parent class.
-------------------------------------------------------------------------------
6)Can you prevent a class from overriding ?
Ans)Yes you can prevent a class from overriding if you define a class as "Sealed " then you can not inherit the class any further.
------------------------------------------------------------------


Q1)difference between array and stack
Ans)
There are two main differences between an array and a stack. Firstly, an array can be multi-dimensional, while a stack is strictly one-dimensional. Secondly, an array allows direct access to any of its elements, whereas with a stack, only the 'top' element is directly accessible; to access other elements of a stack, you must go through them in order, until you get to the one you want
------------------------------------------
Q2)Suppose you have a DataTable having 100,000 rows and 50 columns. Now you've create array of perticular column values, how will you do that?
Ans)
It's simple.
for C#
object[] arr = Array.ConvertAll(dataTable.Select(), (DataRow r) => r[]);
for VB
dim arr as Object() = Array.ConvertAll(Of DataRow, Object)(dataTable.Select(), Function(r as DataRow) r());
------------------------------------------------------------
Q3)Can we assign values to read only variables?if yes then how?
Ans)
yes, we can assign values to read only variables either at a time of declaration or in constructors
-------------------------------------------------------------------
4)Difference between Abstract class and interface?
Ans)
1.Through the abstract class we cannot achieve the multiple inheritance in c-sharp. while by interface we can.
2. We can declare the access modifier in abstract class but not in interface. Because by default everything in interface is public
-----------------------------------------------------------------------
5)You can derive an abstract class from another abstract class. In that case, in the child class it is optional to make the implementation of the abstract methods of the parent class....!
Ans)
Select from following answers:
True
False
No Idea
True
If the derived class is also an abstract class then it is not mandatory to implement the abstract method of the parent class.
-------------------------------------------------------------------------------
6)Can you prevent a class from overriding ?
Ans)Yes you can prevent a class from overriding if you define a class as "Sealed " then you can not inherit the class any further.
------------------------------------------------------------------

Exception handling Questions

Q1)How to use Exception Handling?
Ans)
What is Exception?
An Exception is an unexpected error or problem.
What is Exception Handling?
It is a method to handle the error and solution to recover from it which makes the program to work smoothly.

What is try Block?
The try block consists of the code that might generate an error.
This try block must be associated with one or more catch blocks or by finally block.
The try block may not have a catch block associated with it every time but in this case,it must have a finally block associated with it instead of catch block.

Example:

Format1



try

{

//Code that might generate error

}

catch(Exception error)

{

}



Format2



try

{

//Code that might generate error

}

catch(ExceptionA error)

{

}

catch(ExceptionB error)

{

}



Format3



try

{

//Code that might generate error

}

finally

{

}



What is catch Block?
catch block is used to recover from error generated in the try block.
In case of multiple catch blocks,only the first matching catch block is excecuted.
you need to arrange the multiple catch blocks from specific exception type to more generic type.
If none of the matching catch blocks are able to handle the exception, the default behaviour of web page is to terminate the processing of the web page.

Example:

Format1



try

{

//Code that might generate error

}

catch(Exception error)

{

//Code that handle errors occurred in try block

}



Format2:



try

{

//Code that might generate error

}

catch(DivideByZeroException error)

{

//Code that handle errors occurred in try block

//It is the most specific error we are trying to catch

}

catch(Exception error)

{

//Code that handle errors occurred in try block

//It is not specific error we are catching

}

catch

{

//Code that handle errors occurred in try block

//It is the least specific error in hierarchy

}



What is finally Block?
The finally block contains the code that executes,whether an exception occurs or not.
The finally block is used to write code to close files,database connections,etc.
Only one finally block is associated with each try block.
finally block must appear only after the catch block.
If there are any control statements such as goto,break or continue in either try or catch block,the transfer happens only after the code in the finally block is excecuted.
If the control statements are used in finally block,there occurs a compile time error.

Example:

Format1



try

{

//Code that might generate error

}

catch(Exception error)

{

//Code that handle errors occurred in try block

}

finally

{

//Code to dispose all allocated resources

}



Format2



try

{

//Code that might generate error

}

finally

{

//Code to dispose all allocated resources

}
-----------------------------------------------
Q2)"Viewstate information does not automatically transfer from page to page. It cannot be tracked across pages". Is the statement true ?
Ans)
Select from following answers:

Yes
No
Maybe


Yes, the above statement is true.

Viewstate information cannot be tracked across pages. You can use session or querystring to track anything from one page to another.

Note: Do not store large amount of data on the page using viewstate because it will slow down the page load process.
------------------------------------------------
Q3) What is the use of throw statement?
Ans)
A throw statement is used to generate exception explicitly.
This throw statement is generally used in recording error in event log or sending an Email notification about the error.
Avoid using throw statement as it degrades the speed.

Example:

try

{

//Code that might generate error

}

catch(Exception error)

{

//Code that handle errors occurred in try block



throw; //Re throw of exception to add exception details in event log or sending email

}



//Code that handle errors occurred in try block

}

finally

{

//Code to dispose all allocated resources

}



Format2



try

{

//Code that might generate error

}

finally

{

//Code to dispose all allocated resources

}
----------------------------------------------------------

4)How to manage unhandled Exception?
Ans)
You can manage unhandled exception by configuring the element in web.config file.
It has 2 attributes:

Mode Attribute:It specifies how the custom error page should be displayed.
It has 3 values:
on - Displays custom error pages at both the local and remote client.
off - Disables custom error pages at both the local and remote client.
RemoteOnly - Displays custom error pages only at the remote client as it displays default asp.net error page for local machine.This is default setting in web.config file.
defaultRedirect:It is an optional attribute to specify the custom error page to be displayedwhen an error occurs.
The custom error page is displayed based on http error statusCode using error element inside the customError element.
If none of the specific statusCode matches with it, it will redirect to defaultRedirect page.
-----------------------------------------------
5)Difference between catch(Exception error) and catch
Ans)
The code below explains the difference between catch(Exception error) and catch


try

{

//Code that might generate error

}



catch(Exception error)

{

//Catches all Cls-complaint exceptions

}



catch

{

//Catches all other exception including the Non-Cls complaint exceptions

}




Q1)How to use Exception Handling?
Ans)
What is Exception?
An Exception is an unexpected error or problem.
What is Exception Handling?
It is a method to handle the error and solution to recover from it which makes the program to work smoothly.

What is try Block?
The try block consists of the code that might generate an error.
This try block must be associated with one or more catch blocks or by finally block.
The try block may not have a catch block associated with it every time but in this case,it must have a finally block associated with it instead of catch block.

Example:

Format1



try

{

//Code that might generate error

}

catch(Exception error)

{

}



Format2



try

{

//Code that might generate error

}

catch(ExceptionA error)

{

}

catch(ExceptionB error)

{

}



Format3



try

{

//Code that might generate error

}

finally

{

}



What is catch Block?
catch block is used to recover from error generated in the try block.
In case of multiple catch blocks,only the first matching catch block is excecuted.
you need to arrange the multiple catch blocks from specific exception type to more generic type.
If none of the matching catch blocks are able to handle the exception, the default behaviour of web page is to terminate the processing of the web page.

Example:

Format1



try

{

//Code that might generate error

}

catch(Exception error)

{

//Code that handle errors occurred in try block

}



Format2:



try

{

//Code that might generate error

}

catch(DivideByZeroException error)

{

//Code that handle errors occurred in try block

//It is the most specific error we are trying to catch

}

catch(Exception error)

{

//Code that handle errors occurred in try block

//It is not specific error we are catching

}

catch

{

//Code that handle errors occurred in try block

//It is the least specific error in hierarchy

}



What is finally Block?
The finally block contains the code that executes,whether an exception occurs or not.
The finally block is used to write code to close files,database connections,etc.
Only one finally block is associated with each try block.
finally block must appear only after the catch block.
If there are any control statements such as goto,break or continue in either try or catch block,the transfer happens only after the code in the finally block is excecuted.
If the control statements are used in finally block,there occurs a compile time error.

Example:

Format1



try

{

//Code that might generate error

}

catch(Exception error)

{

//Code that handle errors occurred in try block

}

finally

{

//Code to dispose all allocated resources

}



Format2



try

{

//Code that might generate error

}

finally

{

//Code to dispose all allocated resources

}
-----------------------------------------------
Q2)"Viewstate information does not automatically transfer from page to page. It cannot be tracked across pages". Is the statement true ?
Ans)
Select from following answers:

Yes
No
Maybe


Yes, the above statement is true.

Viewstate information cannot be tracked across pages. You can use session or querystring to track anything from one page to another.

Note: Do not store large amount of data on the page using viewstate because it will slow down the page load process.
------------------------------------------------
Q3) What is the use of throw statement?
Ans)
A throw statement is used to generate exception explicitly.
This throw statement is generally used in recording error in event log or sending an Email notification about the error.
Avoid using throw statement as it degrades the speed.

Example:

try

{

//Code that might generate error

}

catch(Exception error)

{

//Code that handle errors occurred in try block



throw; //Re throw of exception to add exception details in event log or sending email

}



//Code that handle errors occurred in try block

}

finally

{

//Code to dispose all allocated resources

}



Format2



try

{

//Code that might generate error

}

finally

{

//Code to dispose all allocated resources

}
----------------------------------------------------------

4)How to manage unhandled Exception?
Ans)
You can manage unhandled exception by configuring the element in web.config file.
It has 2 attributes:

Mode Attribute:It specifies how the custom error page should be displayed.
It has 3 values:
on - Displays custom error pages at both the local and remote client.
off - Disables custom error pages at both the local and remote client.
RemoteOnly - Displays custom error pages only at the remote client as it displays default asp.net error page for local machine.This is default setting in web.config file.
defaultRedirect:It is an optional attribute to specify the custom error page to be displayedwhen an error occurs.
The custom error page is displayed based on http error statusCode using error element inside the customError element.
If none of the specific statusCode matches with it, it will redirect to defaultRedirect page.
-----------------------------------------------
5)Difference between catch(Exception error) and catch
Ans)
The code below explains the difference between catch(Exception error) and catch


try

{

//Code that might generate error

}



catch(Exception error)

{

//Catches all Cls-complaint exceptions

}



catch

{

//Catches all other exception including the Non-Cls complaint exceptions

}




For Final Year Students of Computers

Q1) Tell in brief, the difference between Development and Production Environment ?
Ans)

Development Environment – It is the place where we develop our application/product. Here all the coders or programmers develops the application/product by writing code.

Production Environment – When the application/product is ready for release to the end-users. When that application/product executes or run in the target machine live.
Q1) Tell in brief, the difference between Development and Production Environment ?
Ans)

Development Environment – It is the place where we develop our application/product. Here all the coders or programmers develops the application/product by writing code.

Production Environment – When the application/product is ready for release to the end-users. When that application/product executes or run in the target machine live.