.NET Framework Exclusive Interview Questions and Answers (46) - Page 1

  • A joint initiative from DotNetFunda.Com and Questpond.
  • A one stop place on the internet to get trusted and proven Interview Questions (based on more than a decade of experience in this field) to ensure the success of the candidates.
  • You will find almost all Interview questions from Questpond here and this list is growing day by day with all latest and updated interview questions.

46 records found.

Get 650+ Questpond's Interview videos on discount

What is the difference between app.config, web.config and machine.config ?

In this .NET Interview questions interviewer expects two things. First the importance of configuration and second in which scenarios are the above file applicable. So lets answer the question in two parts.


The importance of config files
==================================================
App.config, web.config and machine.config are files which store configuration data in XML


format. We need configuration data at application level or at machine/server level.


Scenarios in which the above config files are used
===================================================
Machine.config file stores configuration information at system level. It can contain configuration information like timeout in ASP.NET application, requestLimit, memoryLimit, and ClientConnectedCheck etc.


Generally we have two kinds of application web application and windows application. Web.config file stores configuration data for web applications and app.config file store configuration information for windows application.


Application level configuration data can be like connection strings,security etc.


Some connected questions from this question which the interviewer can ask
================================================================================
Where do you store connectionstring ?.
How do you encrypt connection string?
How do you read configuration data from web.config or app.config file in .NET ?
Can we have two web.config files for a web application.


Regards,




 


.NET Interview questions for Interfaces:- If A class inherits from multiple interfaces and the interfaces have same method names. How can we provide different implementation?.

This is again one those typical .NET Interview questions which move around interfaces to confuse the developer.


For providing different implementation you can qualify the method names with interface names as as shown below. A reference to I1 will display "This is I1" and reference to I2 will display "This is I2". Below is the code snippet for the same.

interface I1 
{
void MyMethod();


interface I2 

void MyMethod(); 


class Sample : I1, I2 

public void I1.MyMethod() 


Console.WriteLine("This is I1"); 
}
public void
I2.MyMethod() 

Console.WriteLine("This is I2"); 

}  
}


50 .NET Interview questions and answers 


 


.NET and OOP interview questions :- What is the difference between abstraction and encapsulation ?

This is a very typical .NET  interview question which confuses most of the .NET professionals. Both abstraction and encapsulation look similiar , but they have huge differences between them.


Abstraction is nothing but simplifying objects while encapsulation is hiding complexity.


Encapsulation implements abstraction. Abstraction is a thought process which happens during planning phase.  While encapsulation implements abstraction by using access modifiers ( private,public, protected,internal and protected internal).


Regards,


SQL Server interview question :- Select record with the second lowest value from the below customer table?

Below is a simple customer table with 3 fields code , name and amount. Can you select the customer with second lowest amount. This is one of the favorite questions which is asked to test your SQL Server skills.
























Code Name Amount
1001 pqr 200.00
1002 raju 100.00
1004 shiv 300.00
1007 shaam 400.00

Below is the answer. It can be accomplished by using sub queries. First select the min and then get all records which are more than the min and select top 1 from the same. Below goes the query.

select top 1 * from tbl_Customer touter where touter.Amount > (SELECT
min(tinner.Amount)
  FROM [Customer].[dbo].[tbl_Customer] as
tinner)
  order by touter.Amount asc


Some time interviewers can trick you questions like select the second top. In the subquery we just need to change the same to max.


 


c# interview question :- Why is stringbuilder concatenation more efficient than simple string concatenation?

This question is one of the favorites question which comes during c# interviews  and the interviewer is not only expecting which one of them is more efficient. But he is also expecting the reason for the same.


In order to understand the same better lets consider the below scenario where we have two lines of code which does string concantenation.


For a simple string concantenation code shown below it will create 3 copies of string in memory.


 

//The below line of code Creates one copy of the string
string str =
"shiv";

/* The below line of  code creates three copies of string object one for
the concatenation  at right hand side and the other for new value at the
left hand side. The first old allocated memory is sent for garbage
collection.*/
str = str + "shiv";


When you use the string builder for concatenation it will create only one copy of the object.


 

/* The below code uses string builder and only one
object is created as
compared to normal string where we have 3 copies created*/
StringBuilder
objBuilder = new StringBuilder();
objBuilder.Append("shiv");


Ok now summarizing what should we say to the interviewer.


String is immutable. Immutable means once assigned it can not be changed. Thats why it creates more copies of the object as it can not use the same instance.String builder is mutable , in other words the same object will changed rather than creating new objects.


So string builder is more efficient as compared to simple string concatenation.


Regards,


If you are said to improve .NET code performance what will you do ?

These kind of questions are very generic. Just pick up 5 best tips you know our have implemented and say it before the interviewer. Below goes my 5



  • Use stringbuilder as compared to normal string concatenation.
  • Use stored procedure rather than inline sql code.
  • Use caching for  frequently used data.
  • Use generics collection as compared to simple collection , to avoid boxing / unboxing.
  • Remove unnecessary boxing and unboxing code.
  • In case you are using unmanaged code use the dispose final function for clean up.



.NET interview question on generics :- How does performance increase by using generic collection ?

When we use normally .NET collection objects there is lot of boxing and unboxing. When we create a  collection which is a generic collection its strongly typed. As its strongly typed boxing and unboxing gets eliminated and thus increasing performance.




ASP.NET interview question:-What is the difference between render and prender event ?

This is again a very nice .NET interview question and  the question can be confusing because of the common word "render". Now ASP.NET page has 4 important events. Init , Load , validate , event and render (Remember SILVER).

Now the final render is a actually a two step process.


1- First the ASP.NET UI objects are saved in to view state.
2- loaded viewstate is assembled to create the final HTML.


The first step is pre-render event and the second step is the render event.


Prerender


This is the event in which the objects will be saved to viewstate.This makes the PreRender event the right place for changing properties of controls or changing Control  structure.Once the PreRender phase  is done those changes to objects are locked in and the viewstate can not be changed. The PreRender step can be overridden using OnPreRender event.


Render.


Render event assembles the HTML so that it can be sent to the browser.In Render event developers can write custom HTML  and override any HTML which is created till now.The Render method takes an HtmlTextWriter object as a parameter and uses that to output HTML to be streamed to the browser. Changes can still be made at this point, but they are reflected to the client only i.e. the end browser.




ASP.NET Interview question :- What are HttpHandler and HttpModules and how do they differ?

Both the above concepts are rarely used by developers but mostly asked in .NET interviews ;-).

The prime  and common goal of HttpHandler and httpModule is to inject pre-processing logic before the ASP.NET request reaches the IIS server.


HttpHandler is a extension based processor in other words pre-processing logic is executed depending on file extensions. For instance sometimes you would like to check that a person should be above age of 18 if he is trying to view any  files with extension *.MP4.


HttpModule is event based processor. ASP.NET engine emits out lot of events as the request traverses over the request pipeline. Just to name some events beginrequest,authorizerequest,authenticaterequest etc. By using HttpModule you can write logic in these events. These logic get executed  as the events fire and before the request reaches IIS server.


So a short answer for the above .NET interview question would be HttpHandler is a extension based processor while HttpModule is a event base processor. Both of them help to inject pre-processing logic before the ASP.NET request reaches the IIS server.




C# Interview questions:- What role did your play in your current project?

This is again a great c# interview question , but .NET professionals tend to answer this question in one liners like i am a developer , project manager.


In todays world people expect professionals who can do multitasking. The best way to approach the answer is by explaining what things did you do in the complete SDLC cycle. Below goes my version of the answer , you can tailor the same as per your needs.


My main role in the project was coding , unit testing and bug fixing. Said and done that i was involved in all phases of the project.

I worked with the business analyst in the requirement phase to gather requirements and was a active member in writing use cases.

I also assisted the technical architect in design phase. In design phase i helped the architect in proof of concept  and putting down the technical design document.

My main role was in coding phase where i executed project with proper unit testing.

In system integration test and UAT i was actively involved in bug fixing.


Other than the project i help COE team for any kind of RND and POC work.


In case you are doing some extra activities in the company like helping COE , presales team or any other initative do speak about the same.


Regards,


.NET interview question :- Who is faster hashtable or dictionary ?

This is again a typical collection .NET interview question. Dictionary is faster than hashtable as dictionary is a generic strong type. Hashtable is slower as it takes object as data type which leads to boxing and unboxing.


Below goes the same code for hashtable and dictionary.


 

Hashtable hashtable = new Hashtable();
hashtable[1] =
"One";
hashtable[2] = "Two";
hashtable[13] = "Thirteen";


 

var dictionary = new Dictionary<string,
int>();
dictionary.Add(i.ToString("00000"),
10);
dictionary.Add(i.ToString("00000"), 11);


 


Regards,




c# Interview question :- Can you explain difference between Pascal notation,Camel notation and hungarian notation ?

The above c# interview question is asked to ensure if you have used coding standards in your project. All the above 3 things are  nothing but naming conventions which are followed in programming languages to ensure a clean code. Below is the explanation of each naming convention.


Pascal Notation- In this naming convention all starting letter of the words are in Upper Case and other characters are lower case.


Example: SupplierCode


Camel Notation- In this naming convention first character of all words, except the first word are Upper Case and other characters are lower case.


Example: supplierCode


Hungarian notation - In this naming convention the variable name starts with group of small letter which indicate data type.


Example: bLoop ( b indicates its a boolean type),iSum ( i indicated its a integer data type).


Regards,


.NET Interview question :- What coding standards did you followed your projects ?

This is a very general .NET interview question.

Normally properly planned companies have a checklist of what kind of naming convention to follow. In .NET interview its very difficult to speak about the whole checklist as we have limited time.

The expectation of the interviewer is that you should speak about pascal,camel and hungarian naming conventions and where did you use what.So below goes a short answer.


Our organization had a naming convention document which was supposed to be followed by all projects in the organization. As per the document we where using three types of naming conventions across the project :- Pascal , Camel and Hungarian.


All class names , function names , method names , namespace names where using pascal convention. i.e the first letter capital with every first word capital.ex CustomerCode


All variables , input/output variable , local variables , class level variable , global variables where using Camel notation. i.e. the first letter small and then the first letter of the subsequent words capital.ex count , customerData


For the UI obejct we where using hungarian notation. In this the prefix defines the datatypes i.e. txtCode , cmbCountries.


For database we used Hungarian notation where the prefix defines the data base object types. i.e. tblCustomer , uspSelectCustomer,fngetValue,trgInsert.


Regards,


c# interview questions :- What are the benefits of three tier architecture ?

This is a very popular c# interview question.In 3 tier architecture / layer we divide the project in to 3 layers UI , Middle  and DAL.  Due the modular approach we have 2 big advantages


Reusability :- You can reuse the middle layer with different user interfaces like ASP.NET , windows etc. You can also reuse you DAL with different projects.


Maintainability :-  When we change in one layer due to the modular approach it does not have ripple effect on other layers. we have to do less amount of changes in other layer when we change logic of one layer.


Regards,


.NET interview questions :- What is the use of private constructor ?

This is one of those .NET interview question which is asked from the perspective to test if you understand the importance of private constructors in a class.


When we declare a class constructor as private , we can not do 2 things:-



  • We can not create a object of the class.
  • We can not inherit the class.

Now the next question which the interviewer will ask , whats the use of such kind of class which can not be inherited neither instantiated.


Many times we do not want to create instances of certain classes like utility , common routine classes. Rather than calling as shown below


 

clsCommon common = new clsCommon();
common.CheckDate("1/1/2011");


You would like to call it as


 

clsCommon.CheckDate("1/1/2011");




.NET interview questions :- Can you explain architecture of your project ?

This is normally the first .NET interview question which pops up in .NET and C# interviews. Personally i think your full  .NET interview ahead depends on how you will answer this question.


Common mistakes :- Many developers make a common mistake of answering this question by saying that we have used C# , SQL server , ASP.NET etc. But please do note that the question is, what is the architecture of your project and not technology.


So a typical answer will be something as below. Please note your answer will vary as per your architecture and structure.


"My current architecture is a simple 3 tier architecture with UI in ASP.NET , middle layer are simple .NET classes and DAL is using enterprise application blocks.

The UI  is responsible to take user inputs , all my business validations are centrally located in middle layer and the data access layer is responsible to execute stored procedured and SQL queries to SQL Server.

Strongly typed business objects are used to pass data from one layer to other layer. The database of the project is in a 3rd normal form."

So first start with the overall architecture , talk about each layer , how data is passed between each layer and the database design structure.

One very important tip if you can draw a diagram and explain....I think you have the job.





 


 


C# interview questions :- In ADO.NET What is connection, command, datareader and dataset object ?

Connection: - This object creates a connection to the database.  If you want to do any operation on the database you have to first create a connection object.


Command: - This object helps us to execute SQL queries against database. Using command object we can execute select, insert, update and delete SQL command.


Data reader: - This provides a recordset which can be browsed only in forward direction. It can only be read but not updated. Data reader is good for large number of records where you want to just browse quickly and display it.


Dataset object: - This provides a recordset which can be read back and in forward direction. The recordset can also be updated. Dataset is like a in memory database with tables, rows and fields.


Data Adapter: - This object acts as a bridge between database and dataset; it helps to load the dataset object.




.NET interview question video :-what is the difference between convert.tostring() and tostring() functions ?

This is one of those famous .NET interview question which keeps coming up now and then. To answer precisely and shortly convert.tostring handles nulls while simple tostring() function does not handle null. Below video demonstrates the same practically.







C# interview question :- What is Serialization in .NET ?

Serialization is a process by which we can save the state of the object by converting the object in to stream of bytes.These bytes can then be stored in database, files, memory etc.


Below is a simple code of serializing the object.


MyObject objObject = new MyObject();


objObject.Value = 100;              

// Serialization using SoapFormatter


SoapFormatter formatter = new SoapFormatter();


Stream objFileStream = new FileStream("c:\\MyFile.xml", FileMode.Create, FileAccess.Write, FileShare.None);


formatter.Serialize(objFileStream, objObject);


objFileStream.Close();


 


 Below is simple code which shows how to deserialize an object.


 

//De-Serialization


Stream objNewFileStream = new FileStream("c:\\MyFile.xml", FileMode.Open, FileAccess.Read, FileShare.Read);


MyObject objObject =(MyObject)formatter.Deserialize(objNewFileStream);


objNewFileStream.Close();




ASP.NET Interview questions :- What is the advantage of using MVC pattern?

MVC is one of the most used architecture pattern in ASP.NET and this is one of those ASP.NET interview question to test that do you really understand the importance of model view controller.




  • It provides a clean separation of concerns between UI and model.


  • UI can be unit test thus automating UI testing.


  • Better reuse of views and model. You can have multiple views which can point to the same model and also vice versa.


  • Code is better organized.



More .NET FRAMEWORK Interview Questions & Answers here

Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Exclusive Interview Questions and Answers Categories