.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> .Net Framework >> Post New Resource Bookmark and Share   

 Subscribe to Articles

18 most asked .NET , C# interview questions and answers Part 3

Posted By:Shivprasad koirala       Posted Date: June 06, 2011    Points: 200    Category: .Net Framework    URL: http://www.questpond.com  

Lets continue with the 3rd part of 18 .NET interview question series. If you want to see the past 2 articles you can visit for part 1 at http://www.dotnetspark.com/kb/4089-18-most-asked-net--c-sharp--interview-questions.aspx and for part 2 at http://www.dotnetspark.com/kb/4114-18-most-asked-net--c-sharp--interview-questions.aspx In this part we will see some important questions on SQL , WCF and ASP.NET
 

                                               

18 most asked .NET , C#  interview questions and answers Part 3

By Shivprasad koirala.

 

                                                               

                                                                    
Introduction
Question 1 :-What are Special Collections?
Question 2:-
How do we do security in WCF?
Question 3:-How do you do Self-Hosting?
Question 4:-What is WSDL?
Question 5:-What is Cross Join and in which scenario do we use Cross Join?
Question 6:-How does index makes search faster?
Question 7:-What coding standards did you followed your projects ?
Question 8:-Why is stringbuilder concatenation more efficient than simple string concatenation?
Question 9 :-How do we write a HttpHandler ?
Question 10:- What is the difference between render and prender event ?

Question 11:-What is SOAP?
Question 12:-What are different types of Validators?
Question 13:-Why do we need Sessions?

Question 14:-How to cache an ASP.NET page?
Question 15:-What are the diferences between INNER JOIN, LEFT JOIN and RIGHT JOIN in SQL Server?
Question 16:-Who is faster hashtable or dictionary ?
Question 17:-What role did your play in your current project?
Question 18:-If A class inherits from multiple interfaces and the interfaces have same method names. How can we provide different implementation?.

Introduction

 

Lets continue with the  3rd part of 18 .NET interview question series. If you want to see the past 2 articles you can visit for part 1 at  http://www.dotnetspark.com/kb/4089-18-most-asked-net--c-sharp--interview-questions.aspx and for part 2 at  http://www.dotnetspark.com/kb/4114-18-most-asked-net--c-sharp--interview-questions.aspx

In this part we will see some important questions on SQL , WCF and ASP.NET


Do view my 500 videos on .NET , C# , WCF , Silverlight , design patterns , ASP.NET , UML by click on .NET interview questions

If you want to have a overview of what kind of questions are asked in .NET interviews do click on this link http://youtu.be/pC3aLkf_A98?hd=1 where i have discussed from overall view of different questions asked during .NET and C# interviews,

If you want to understand the physcology of how .NET interviewer conducts interviewer click on this link  http://youtu.be/3PXspVcSSKE?hd=1

 

What are Special Collections?
Answer:
Special Collection:-Special Collection are nothing but tailored .net collection meant for specific purpose.

There are many types of special collection in .net but let only talk about four important special collection which are mostly used.

The following are the four important special collections

1. CollectionsUtil:-It help us to Create collections that ignores the case in String.

Example:-

Hashtable ObjHash = CollectionsUtil.CreateCaseInsensitiveHashtable();
ObjHash.Add("feroz","he is a developer");
string str = (string) ObjHash["FEROZ"];
MessageBox.Show(str);
2. ListCollection:-Good for Collections that typically contain less number of elements.

Example:- 
ListDictionary ObjDic = new ListDictionary();
ObjDic.Add("feroz", "he is a developer");
ObjDic.Add("moosa", "he is a developer");
3. HybridCollection:- It is combination of ListDictionary and HashTable.When the collection items are less then it will act as ListDictionary and when number of items increases above 10 or above certain number then it will act as a Hashtable Collection.

Example:-
 HybridDictionary ObjHybrid = new HybridDictionary();
 ObjHybrid.Add("feroz", "he is a developer");
 ObjDic.Add("Wasim", "he is a network administrator");
 ObjDic.Add("moosa", "he is a hardware engineer");
4. StringCollection:- It is a very special Collection, which is designed for storing only string items.
 

.NET Interview questions , C# Interview questions , ASP.NET Interview Questions , SQL Server interview questions

 

How do we do security in WCF?
Answer:
In WCF there are two types of Security,transport level security and message level security.

Transport Security:Transport level security happens at the channel level. Transport level security is the easiest to implement as it happens at the communication level. WCF uses transport protocols like TCP, HTTP, MSMQ etc and every of these protocols have their own security mechanisms. One of the common implementation of transport level security is HTTPS. HTTPS is implemented over HTTP protocols with SSL providing the security mechanism. No coding change is required it's more of using the existing security mechanism provided by the protocol.

Message Security:Message level security is implemented with message data itself. Due to this it is independent of the protocol. Some of the common ways of implementing message level security is by encrypting data using some standard encryption algorithm.

Below Diagram illustrate the concept of security in WCF.

.NET Interview questions , C# Interview questions , ASP.NET Interview Questions , SQL Server interview questions

How do you do Self-Hosting?

Answer:
The following steps are followed to do Self-hosting.

Step1:    //Create a URI to serve as the base address
            // Address as well binding

Uri httpUrl = new Uri("http://localhost:8010/MyService/HelloWorld");


Step2: //Create ServiceHost           

 ServiceHost host = new ServiceHost(typeof(ClassLibrary1.HelloWorldService),httpUrl);
Step3: //Add a service endpoint      
host.AddServiceEndpoint(typeof(ClassLibrary1.IHelloWorldService) , new WSHttpBinding(), "");
Step4: //Enable metadata exchange
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;           
host.Description.Behaviors.Add(smb);
Step5: //Start the Service            
host.Open();
Step6: 
Console.WriteLine("Service is host at " + DateTime.Now.ToString());          
Console.WriteLine("Host is running... Press  key to stop");           
Console.ReadLine();
 

What is WSDL?
Answer:
WSDL(Web Services Description Language) is an XML-based language which describes the Web services,Method name,Function name and Input Output parameter.

To see how WSDL look like, just go to Visual Studio create a webservice and run .asmx file you will see the output like below diagram and when you click on service description then the WSDL will be seen.
 

.NET Interview questions , C# Interview questions , ASP.NET Interview Questions , SQL Server interview questions 

  
- http://schemas.xmlsoap.org/wsdl/soap/" 
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" 
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" 
xmlns:tns="http://tempuri.org/" xmlns:s="http://www.w3.org/2001/XMLSchema" 
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" 
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" 
targetNamespace="http://tempuri.org/" 
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
- 
- http://tempuri.org/">
- 
     

- 
- 
- 
   

 
 
 
 
 
+     -     -    
 
 
 

What is Cross Join and in which scenario do we use Cross Join?
Answer:
CROSS JOIN: Cross join is used to return all records where each row from first table is combined with each row in second table.
  Cross join is also called as Cartesian Product join.
  The cross join does not apply any predicate to filter records from the joined table. Programmers can further filter the results of a cross join by using a WHERE clause.

For Example:-  We have following two tables.

Look at the "Product" table:

P_Id ProductName Cost
1 SimplePizza 100.00
2 CheezePizza 200.00
3 DoubleCheezePizza 300.00
4 ChickenPizza 250.00

Note that the "P_Id" column is the primary key in the "Product" table.

Next, we have the "SubProduct" table:

Sub_Id SubProductName Cost
1 Cold Drink 100.00
2 Bread 15.00

Note that the "Sub_Id" column is the primary key in the "SubProduct" table.

There are lots of scenarios where we use the cross join(permutation and combination), below are the example of hotel where customer's gets the detail of combined product and its total cost, So that it is easy to select their respective choice.

Query:- select Product.ProductName,SubProduct.SubProductName,(Product.Cost+SubProduct.Cost)as TotalCost from Product cross join SubProduct

 The output look like below:

ProductName SubProductName TotalCost
SimplePizza Coldrink 200.00
CheezePizza Coldrink 300.00
DoubleCheezePizza Coldrink 400.00
ChickenPizza Coldrink 350.00
SimplePizza Bread 115.00
CheezePizza Bread 215.00
DoubleCheezePizza Bread 315.00
ChickenPizza Bread 265.00
 

How does index makes search faster?

Answer:
For better understanding, let us consider a simple search example which shows differences between a table, declared with index and without index.

Let's first see an example for a table which is created without declaring an index and look how exactly the SQL search engine will perform action. Below diagram will give u better idea.

.NET Interview questions , C# Interview questions , ASP.NET Interview Questions , SQL Server interview questions

In the above example, SQL search engine will search from initial till it finds the respective record and once the record is found it will basically display the record.

Further, When we create an index on any column of a table then the large data get divided like following B-Tree diagram, so that search becomes easier and faster.

 

.NET Interview questions , C# Interview questions , ASP.NET Interview Questions , SQL Server interview questions

                                                B-tree structure of a SQL Server index
For example:-

Suppose we have to search value 25 in an indexed column, the query engine will first look in the "Root Node" to determine which node to refer in the "Branch Nodes". In the above example first "Branch Node" has Value 1 to 20 and the second "Branch Node" has Value 21 to 40, so the query engine will go to the second "Branch Node" and will skip the first "Branch Node" as we have to search Value 25. Same like "Branch Nodes" the query engine will operate the "Leaf Node" to retrieve respected result.

 

What coding standards did you followed your projects ?

Answer:
 

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.

 

Why is stringbuilder concatenation more efficient than simple string concatenation?

Answer:
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.

 

How do we write a HttpHandler ?

Answer:
This is a simple a .NET Interview question .Its a two step process.

First create a class which implements Ihttphandler

public class clsHttpHandler : IHttpHandler
{

    public bool IsReusable
    {
        get { return true; }
    }

    public void ProcessRequest(HttpContext context)
    {
       // Put implementation here.
    }
}

 

Step 2 make a entry in the web.config file.

 



 

What is the difference between render and prender event ?

Answer:
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.

 

What is SOAP?

Answer:
SOAP(Simple Object Access Protocol) is a standard XML format for communicating between Server and Client in WebServices.

The below diagram dipicts an simple request and response using SOAP.

.NET Interview questions , C# Interview questions , ASP.NET Interview Questions , SQL Server interview questions

 

What are different types of Validators?

Answer:
A validator is a computer program used to check the validity or syntactical correctness of a fragment of code or text.

IN ASP.NET there are six different types of Validators.

Required Field Validator.
Regular Expression Validator.
Compare Validator.
Range Validator.
CustomValidator.
Validation Summary

RequiredFieldValidator:-Ensure that the control has a value to assign in it or user does not skip an entry.

For Example:- 

 
 
 

RegularExpressionValidator:-Ensure that the value of the control matches the expression of validator that is specified.This type of validation enables you to check for sequence of character, such as e-mail address,telephone number,postal code and so on.

For Example:- 

 
  // for internet E-Mail.
 

CompareValidator:-Ensure that the value of one control should be equal to value of another control.which is commonly used in password,less than,greater than or equal to.

For Example:-



RangeValidator:-Ensures that the value of the control is in specified lower and upper boundaries or specified range.  You can check ranges within pairs of numbers, alphabetic characters.

For Example:- 


>

CustomValidator:-This control is used to perform user defined validations.

ValidationSummary:-This validator is used to displays a detailed summary on the validation errors that currently exist.

 

Why do we need Sessions?

Answer:
HTTP is a stateless protocol; it can't hold the client information on page. In other words after every request and response the server does not remember the state, data and who the user was. If user inserts some information, and move to the next page, that data will be lost and user would not able to retrieve the information.So, Session provides that facility to store information on server memory.

Below is the diagram to understand in better manner.

.NET Interview questions , C# Interview questions , ASP.NET Interview Questions , SQL Server interview questions
In the above example, when the user request the IIS server for the Page1.aspx then the request is broadcasted to the user/client browser and the connection is broken, Now when the same user request the IIS server for the Page2.aspx then again the request is broadcasted to the user/client browser but this time again the same user is treated as a new user as the connection was broken by IIS server after displaying the Page1.aspx page.
Note:-
So every single time a new request is made the same user is treated as a new one, so in order to maintain this we need Sessions.

 

How to cache an ASP .NET page?

Answer:
Output Cache is used to Cache an ASP.NET page.

Output Cache is called as directives.

The below diagram shows, how exactly the caching is done.

.NET Interview questions , C# Interview questions , ASP.NET Interview Questions , SQL Server interview questions

                               Diagram of Caching.

Caching can be done in three ways as followings.

  1. Cache the complete page.
  2. Cache the portion of the page.
  3. Cache the complete page but a portion is static.

The below diagram will give an idea of Caching different forms.


 .NET Interview questions , C# Interview questions , ASP.NET Interview Questions , SQL Server interview questions

                           Different types of Caching.

The below code snippet shows how to Cache the complete page.
 

<%@ OutputCache Duration="20" Location="Server"  VaryByParam="none" %>

To Cache the portion of the page.we have to add web user control page and the directive is placed at the top of user control page.(.ascx file).

<%@ OutputCache Duration="20" VaryByControl="LiveScore" VaryByParam="*"%>

Now, for Caching the complete page but a portion should be static. we have to add web user control page and later you can define the output cache in the source of the web user control page.

 

What are the diferences between INNER JOIN, LEFT JOIN and RIGHT JOIN in SQL Server?

Answer:
Let us Assume we have following two tables:-

Create a new table as"Customers":
 

Cust_Id    LastName   FirstName  Address City
1    Shaikh Moosa Churchgate Mumbai
2 Khan Salman Bandra Mumbai
3 Shaikh Feroz Mahim Chennai

Note that the "Cust_Id" column is the primary key in the "Customers" table.
This means that no two rows can have the same Cust_Id.
The Cust_Id distinguishes two persons even if they have the same name.
Next, we have the "Orders" table:

Order_Id OrderNo   Cust_Id
1 7895 3
2 4678 3
3 2456 1
4 4562 1
5 4764 15

Note that the "Order_Id" column is the primary key in the "Orders" table and that the "Cust_Id" column refers to the persons in the "Customers" table without using their names.

Notice that the relationship between the two tables above is the "Cust_Id" column.

LEFT JOIN:  Return all rows from the left table, even if there are no matches in the right table.
For Example:- 
                    The Following is the example for LEFT JOIN:

Considering the above two tables:

Query:-  Select * from Customers left join Orders on Customers.Cust_Id = Orders.Cust_Id

The output will look like following:

Cust_Id LastName  FirstName   Address   City Order_Id OrderNo Cust_Id
1 Shaikh Moosa Churchgate Mumbai 3 2456 1
2 Khan Salman Bandra Mumbai NULL NULL NULL
3 Shaikh Feroz Mahim Chennai 1 7895 3
3 Shaikh Feroz Mahim Chennai 2 4678 3

RIGHT JOIN:  Return all rows from the right table, even if there are no matches in the left table.
For Example:- 
                    The Following is the example for RIGHT JOIN:

Considering the above two tables:

Query:-  Select * from Customers right join Orders on Customers.Cust_Id = Orders.Cust_Id

The output will look like following:

Cust_Id LastName FirstName  Address   City   Order_Id OrderNo   Cust_Id
3 Shaikh Feroz Mahim Chennai 1 78958 3
3 Shaikh Feroz Mahim Chennai 2 4678 3
1 Shaikh Moosa Churchgate Mumbai 3 2456 1
NULL NULL NULL NULL NULL 4 4562 4
NULL NULL NULL NULL NULL 5 4764 6

INNER JOIN:  The INNER JOIN keyword return rows when there is at least one match in both tables.
For Example:- 
                   The Following is the example for RIGHT JOIN:
Considering the above two tables:

Query:-  Select * from Customers inner join Orders on Customers.Cust_Id = Orders.Cust_Id

The output will look like following:

Cust_Id LastName FirstName  Address   City   Order_Id OrderNo   Cust_Id
3 Shaikh Feroz Mahim Chennai 1 78958 3
3 Shaikh Feroz Mahim Chennai 2 4678 3
1 Shaikh Moosa Churchgate Mumbai 3 2456 1

 

Who is faster hashtable or dictionary ?

Answer:
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();
dictionary.Add(i.ToString("00000"), 10);
dictionary.Add(i.ToString("00000"), 11);

 

What role did your play in your current project?

Answer:
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.

If A class inherits from multiple interfaces and the interfaces have same method names. How can we provide different implementation?.

Answer:
 

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"); 
}  
}


 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend