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.
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.
class Sample : I1, I2
public void I1.MyMethod()
Console.WriteLine("This is I1");
Console.WriteLine("This is I2");
50 .NET Interview questions and answers
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).
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.
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
FROM [Customer].[dbo].[tbl_Customer] as
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.
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 =
/* 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
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*/
objBuilder = new StringBuilder();
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.
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.
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.
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.
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 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.
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.
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.
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 = "Two";
hashtable = "Thirteen";
var dictionary = new Dictionary<string,
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.
Camel Notation- In this naming convention first character of all words, except the first word are Upper Case and other characters are lower case.
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).
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.
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.
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();
You would like to call it as