Wednesday, December 19, 2012

C# and .NET interview question: -What is short circuiting in C#?

When developers get this .NET interview question many of them get stunned with the name.

Short circuiting occurs when you do logical operations like ‘AND’ and ‘OR’.

 “When we use short circuit operators only necessary evaluation is done rather than full evaluation.
Let me explain the above sentence with a proper example. Consider a simple “AND” condition code as shown below. Please note we have only one “&” operator in the below code.

if(Condition1 & Condition2)

In the above case “Condition2” will be evaluated even if “Condition1” is “false”. Now if you think logically it does not make sense to evaluate “Condition 2”, if “Condition 1” is false.It’s a AND condition right? , soif the first condition is false it means the complete ANDcondition is false and it makes no sense to evaluate “Condition2”.

There’s where we can use short circuit operator “&&”. For the below code “Condition 2” will be evaluated only when “Condition 1” is true.
if(Condition1 && Condition2)

The same applies for “OR” operation. For the below code (please note its only single pipe(“|”).)   “Condition2” will be evaluated even if “Condition1” is “true”. If you think logically we do not need to evaluate “Condition2” if “Condition1” is “true”.

if(Condition1 | Condition2)

So if we change the same to double pipe (“||”) i.e. implement short circuit operators as shown in the below code, “Condition2” will be evaluated only if “Condition1” is “false”.

if(Condition1 || Condition2)

Taken from the best selling interview question book .NETinterview question by Shivprasadkoirala 

Here’s an awesome video on concurrent generic collections in C#.

Thursday, December 13, 2012

C# and .NET interview question: - What are symmetric and asymmetric algorithms?

Simple but important .NET / c# interview question.

Symmetric and Asymmetric are encryption algorithms. In Symmetric we have one key which encrypts messages and the same key helps to decrypt the message. In Asymmetric there are two keys public key and private key. Public key helps to encrypt message and private keys helps to decrypt the message. Everyone has the public key but the private key is held only by the authorized authority


Taken from the best selling interview question book .NET interview question by Shivprasad koirala.

Saturday, December 8, 2012

What is BI Semantic model (BISM) in SQL Server 2012?

Some days back I was installing SQL Server 2012 enterprise service pack 1. During installation when I was running through the setup, it gave me two options (multi-dimensional and tabular) of how I want to install SQL Server analysis service. Below is the image captured while doing installation

At the first glance these options are clearly meant to specify how we want the model design for our analysis service.

Now the first option i.e. “MultiDimensional” was pretty clear as I have been using them right from SQL Server 2005 till today i.e. (Star schema or Snow flake).

After some googling and hunting I came to know about the second option. Let me throw some light on the same and then we will conclude what is BISM.

Now overall we have two kinds of database systems , one is OLTP system where the database design thought process is in terms of tables and normalization rules ( 1st normal form , second normal form and third normal form  database design ) are followed.

The second kinds of systems are OLAP system’s where we mostly design is in terms of fact tables and dimension tables. Cube which is a multi-dimensional view of data is created properly if you design your database as OLAP system.

So in simple words we need to create a DB with OLAP design to ensure that proper cubes structure is created.

Now some times or I will say many times it’s really not feasible to create different structures and then create cubes from them. It would be great if SSAS gives us some options where we can do analysis straight from normalized simple tables.

For instance take simple end users who use “power pivot”. It’s very difficult for them to make understand OLAP models like dimension and fact tables. But yes they do understand tables with rows and columns.  If you see Microsoft excel the format is in terms of tables which have rows and columns and these end users are comfortable with a tabular structure.

 Below is a simple image of how simple end user visualize data in excel i.e. tabular – rows and columns.

That’s where exactly the second option i.e. the “Tabular” mode comes in to picture.

So if we put in simple words BISM (Business intelligence semantic model) is a model which tries to serve simple users / programmers who are comfortable with tabular structure and also maintains professional OLAP models for corporate.

So BISM is a unifying name for both Multi-dimension and tabular models.  So if you are personal BI person who loves ADHOC analysis, you can use power pivot or SSAS tabular IDE to do analysis. And if you are person who is working on a corporate project then Multi-dimension model is more scalable and worth looking in to.

Just a last quick note this is also a favorite SQL Server interview question which is making rounds now a days when SQL Server 2012 topic is discussed.

With all due respect to my publisher I have taken the above answer from my book SQL Server interview questions and answers.

You can also see my blog which has some important for SQL Server interview questions on Colaesce. 

You can also see my video on Can views be updated (SQL Server interview questions) ?

Friday, November 30, 2012

Important SQL Server interview questions on data types: - How many bytes does “char” data type consume as compared to “nchar” data type?

“char” data types consumes 1 byte while “nchar” consumes 2 bytes. The reason is because “char” stores only ASCII characters while “nchar” can store UNICODE contents as well.

In case you are new to ASCII and UNICODE. ASCII accommodates 256 characters i.e.english letters ,punctuations , numbers etc.But if we want to store a Chinese character  or some other language characters then  it was difficult to the same with ASCII  , that’s where UNICODE comes in to picture. An ASCII character needs only 1 byte   to represent a character while UNICODE needs to 2 bytes.

One of my SQL Server friends who had gone for a SQL interview was grilled , whether we can update SQL Server views , I have tried to answer this question here with a video

The above question I have extracted from near to heart book
SQL Server interview questions By Shivprasad koirala by BPB publication

Click to view more from authors on SQL Server interview questions and answers

Monday, November 26, 2012

You are 35 and not a manager – The Indian IT society trauma?

I am not trying to underestimate the position of a manager.  But I hate when people point fingers at me and say “You are 35 and still not a manager, till what age can you code?”.
I am so sorry to be harsh, but I really hate those people who for various reasons think that programmers are some kind of useless mass on earth. Do not contradict that many do not think they think and its truth.

By grace of god I am personally at a position where I do not care andI love programming, technology and would like to spend rest of life doing the same. 

But with that statement many good developers would have been converted to bad managers overnight.  Frankly I blame the Indian IT society who thinks after a certain age a person is less capable of  programming.
Leaving my so called personal confidence aside
thought to look at the other side of the mirror on, why majority developers are forced to become managers.

Social trauma

For some reasons when someone (especially senior managers) knows you are a developer they start thinking about you as a person who is not a decision maker or probably they  just imagine you as  technical lover  who has  no understanding of how to do business .

Some people also go one step further to conclude that a pure technical person can never be leader or motivate any one.

A person at the age of 30 is considered a failure, if he is involving himself in coding.

A manager allocating resources from a excel sheet is more respected by IT society than a developer or a technical architect slogging to solve problems.

Major people of IT society envy how a manager has his own cabin, how he commands, how he does so called project management, allocates resources, motivates people (some project managers have the illusion that they are bill gates) , implements processes blah blah. This is the first reason I think that a technical person starts thinking that a manager is a better fit than a technical role. He starts dreaming about the comfort zone and luxury enjoyed in a managerial position.

Technical person does not have money or the power
In India the salary difference of a senior technical person and equivalent experience manager is considerable. 

A manager who is working on a excel sheet, PPT and documents are paid more than technical people who actually create the software.

Adding to everything some senior managers have this feeling that a technical person can be made happy by giving challenging technical work and he will not crib for anything. Oh yes, I love technical work but at the end of the day I have to show my face to the family.

I am not saying start paying the senior technical person’s more. But this difference should be minimized so that atleast senior technical people start feeling that yes this role at this is age is also appreciated by the industry.

Technical architect position a joke

Many people can argue that, then choose the path of a technical architect. Oh, gosh, this position in Indian IT industry is abused (sorry for crossing limits) to a extent that there are people who refrain to take this position any more. I sometimes think this position is created to create a illusion that they are growing in their career.

As a technical architect, they expect you do everything. Right from technical solution, to nitty gritty problem solving and providing hands on solution to the developer’s.

Wondering when Indian IT industry will start respecting t
echnical people , give them appropriate respectable position , his words are considered during decision making and he stands shoulder to shoulder with the project manager  in terms of decision making.Sorry for the loud mouth. I do not have the genes to write these kinds of article but I am sure it echoes feelings of lot of technical people out there.Would like to hear from you guys, if your organization has a proper road map for techies and do they really feel comfortable with the road map.

Thursday, November 22, 2012

C# and ASP.NET MVC (Model view controller) interview questions and answers:- What are MVC partial views and how can we call the same in MVC pages?

ASP.NET MVC (Model view controller) partial view is a reusable view (like a user control)which can be embedded inside other view. For example let's say all your pages of your site have a standard structure with left menu,header and footer as shown in the image below.

For every page you would like to reuse the left menu, header and footer controls.So you can go and create partial views for each of these items and then you call that partial view in  the  main view.

When you add a view to your project you need to check the “Create partial view” check box.

Once the partial view is created you can then call the partial view in the main view using "Html.RenderPartial" method as shown in the below code snippet'

Below is an important SQL server interview question and answers video:-

Do visit us for c#  and ASP.NET MVC interview question and answers

See more stuffs on C#/ASP.NET interview questions 


Click here to see more C# and ASP.NET interview questions and answers

Thursday, November 8, 2012

SQL Server Interview Question and answers: - How does index affect insert, updates and deletes?

First let me give a short answer so that you can please the interviewer and get your job. If you are inserting heavy data on table which have clustered indexes that will lead to page split. Due to heavy page splits the performance can degrade. So a proper balance of indexes should be maintained for tables which are heavy in transactions and have clustered indexes created.

Now let’s go for a big explanation of what exactly is a page split.

Indexes are organized in B-Tree structure divided in to root nodes, intermediate nodes and leaf nodes. The leaf node of the B-tree actually contains data. The leaf index node is of 8 KB size i.e. 8192 bytes. So if data exceed over 8 KB size it has to create new 8 KB pages to fit in data. This creation of new page for accommodating new data is termed as page split.

Let me explain you page split in more depth. Let’s consider you have a simple table with two fields “Id” and MyData” with data type as “int” and “char(2000)” respectively as shown in the below figure. “Id” column is clustered indexed.

That means each row is of size 2008 bytes (2000 bytes for “MyData” and 8 bytes for “Id”).

So if we have four records the total size will be 8032 bytes (2008 * 4) that leaves 160 bytes free.Do looat the above image for visual representation.

So if one more new record is added there is no place left to accommodate the new record and the index page is forced to go for an index page split.

So the more we have page splits, the more the performance will be hit as the processor has to make extrefforts to make those page split’s, allocate space etc.

Here’s a awesome video on one more tough SQL Server interview question: -What are CTE (Common table expression) ? , you watch the same from by clicking on

Taken from the best selling SQL Server interview question book, you can see more about the book by clicking on  SQLServer interview questions book Dotnet interview questions and answers book  

See more stuffs on  SQL server interview questions


Click here to view more SQL server interview questions and answers .

Thursday, October 11, 2012

.NET Interview questions and answers: -What are different access modifiers?

Taken from my book.NET interview questions
There are 5 access modifiers. Access modifiers define scope for members.

·     Private:  Accessible only with in the class.
·     Protected: - Accessiblewith in the class and in derived classes.
·     Friend (internal in C#):- Accessible anywhere within the current project.
·     Protected friend (protected internal in C#):- Accessible with current project and derived classes.
        ·       Public: - Accessible everywhere.


One of interesting .NET interview question: -What is the difference between string and string builder ?

Monday, October 8, 2012

SQL Server SSIS Interview questions: -What is the difference between “For loop container” and “Foreach loop container”?

The “For Loop Container” executes specified number of times like 10 times, 20 times until the specified condition is met.

The “Foreach Loop Container” runs over an iterator. This iterator can be files from a folder, records from ADO, data from a variable etc.

In case you are fresher to SSIS, SSAS and SSRS you can start seeing our step by step videos from


Get more C# training stuffs from author's blog

Saturday, September 15, 2012

c# interview question :- What is the difference between Debug and Release?

See the following C# / .NET training video: - In this video we will understand how c# debug and release compile modes are different and when to use them. Debug is mainly meant for development environment while release is meant for production environment.

See for more stuffs on c# interview questions and answers


Click to view more from author's on C# training

Friday, June 8, 2012

Site is under maintenance, please visit later: - ASP.NET trick

24 x 7 uptime guaranteed

As a web site owner we all boast about 24 x 7 uptime. But somewhere down below in our hearts we know it’s difficult. We need to bring down the website for maintenance, fixingdefects, upgrading etc.

Easy way…

As an innocent c# ASP.NET developer you would think how about just stopping IIS web server, do your activity(maintenance, fixing defect etc.) and then start the IIS again.

While this looks to be a but obvious way of solving the problem but it’s not the best way if we consider the end user perspective. The end user would see an ugly screen as shown below leading to more confusion.

Rather than end user seeing that kind of absurd screen how about showing something more better and informative like: - “Site is under maintenance and will be live till 3:00 AM”.

Going offline graciously:-App_Offline.htm

Also I would like to highlight here it’s not about showing the error message but technically we would like to ensure that the following things happen in IIS:-
  • Application domain under which the website is running is brought down.
  • All incoming request coming to the ASP.NET site needs to stopped.
  • All request to be routed to the temporary page which is created.
  • After maintenance the application domain should be loaded and the incoming request should be processed in a normal manner.
Thanks to Microsoft they always understand our needs. The proper way of approaching this problem is to create a simple “App_offline.htm” file in your application root directory. In this “App_offline.htm” you can put your user friendly message which the end users can see when the site is under maintenance.
Once done you can delete the file and your web site app domain is loaded and the normal life continues.

You can visit my site for
C# and .NET interview questions and in case you are a fresher you can attend FREE C# training by clicking on C# training videos.

Take a quick look as revision for practical video on "Site is under maintenance"

Monday, June 4, 2012

C# and .NET interview advice for freshers: - Not getting a job for a year should I put fake experience, switch to DBA or pay money for getting a job?

As a .NET interview questions author I always get lots of emails. One of the common things which people ask should I put a fake experience. Below is an answer to one such email.

Sir I've completed in 2011 ,,,,and searching for a job,,,, I was trained on .NET from NIIT institute ,,,, I've faced some .NET interviews but they are asking for money to pay them,,,,

If someone says pay money to get a job that means they do not need you, you are kind of a baggage on them. Also beware it can be a fraud also. Lately lot of small size software companies and training institutes who are not doing well have turned up to these kind of activities.

When we say we are doing a job, means we are helping company to grow and company pays money in return. So people who are asking for money straight say No No , if that means sitting at home for some time that’s fine, enjoy family.

and other side i am jobless till now and its been 1year,,,and now i don't understand what to do now to see my self as a engineer

If you are jobless for a year you need to see what’s going on wrong. Do connect me personallyfor a mock on .NET interview so that I can personally judge to see what is wrong.

IT market is not so bad. It must be a bit strict for fresher’s but not that horrible as you see. See one is that you are jobless for a year and the other is that in this 1 year you have been to at least 15 interviews and you got till the last round. So if you belong to later part of it that means you are doing well and you should get a job soon.

I personally understand what it means to be at home for a year. But believe me when you get good positions in life ahead you will cherish this struggle and you will be proud of the same.

How about switching to DBA

Courtesy: -

There's a saying in Hindi,DusrokagharSuhanalagtahai( The other side of the grass is always green). .NET, c# has large number of jobs as compared to DBA. Definitely DBA has its own Niche but the numbers of jobs are less. So if for C# you have 100 jobs then for DBA you will have 10. In those 100 c# jobs the number of applicants will be 1000 while in DBA it will be 10.

So one scores high in the number of jobs while the other has less competition. My suggestion would be you have already been trained in NIIT , you are already in full swing of searching a job , stick to .Net for now. You can switch to DBA later when you have a job on hand.

Will a fake 1 year experience help me?

For one Lie you will have to tell 100 Lies ahead. Smaller companies look for people who can code and complete their project. Bigger and mid-level companies look for experience. So start with smaller companies, do not expect sky rocketing salary, be truthful, show your expertise by showing some sample projects. Let them you are serious as well as competent.

I know you will not believe as you are jobless for a year but TRUTH finally wins.

C# interview questions: - What’s the difference between String and String Builder?

Also visit my site for more C# training.

Sunday, May 20, 2012

The unsung hero, Volatile keyword: - c# threading

The unsung hero, Volatile keyword: - c# threading

My mad and blind love with c# threading

When I first saw c# threading code, I just falled in love forever. As days passed by the power and simplicity of “System.Threading” namespace converted my love in to blind love.

Thread t1 = new Thread(SomeThread);

In case you have not still fallen in love and new to c# threading, you can start looking at my c# training threading video from here.

The blind love was but obvious because in today’s modern world parallel task execution is compulsory component.My love helped me to please users with mind blowing UI interfaces, multi-threaded batch processes, until one day…..

End of blind love with c# threads

But one fine day my love with c# thread’s had a bump.I had two threads running and both where updating the same local variable.  The updation done by one thread was not visible to the other thread.

Let me detail what I am saying. I had create a local variable called as “_loop” as shown in the below abstract code snippet. This variable was set to ‘true’ by default.

class Program
bool _loop = true;


In the same application I had created one function called as “SomeThread” which will run until the “_loop” is true.

private static void SomeThread(object o1)
while (o._loop)

From the main thread I was spawning this some thread which was running the loop continuously. In this main thread I was setting the “_loop” to false. In other words the infinite loop of “SomeThread” should stop and exit…VOILA it did not.

static void Main(string[] args)
Thread t1 = new Thread(SomeThread);
o1._loop = false;

Below is the complete source code, you download and see it for yourself.!257&authkey=!ABOTw_YQ_czfnNc

bool _loop = true;
static void Main(string[] args)
            Program o1 = new Program();
            Thread t1 = new Thread(SomeThread);
            o1._loop = false;
            Console.WriteLine("Value Set to false");
        private static void SomeThread(object o1)
            Program o = (Program)o1;
            Console.WriteLine("Loop Starting...");
            while (o._loop)
            Console.WriteLine("Loop Stopping...");

If you run the above code you can see the infinite loop starting, but I does not end even if the value was set to “false”.

You can also see the actual video demo of the code by clicking on c# training for threading .
Note :- When you run the code ensure that you have selected release  with CNTRL + F5 pressed.

Why did my love ditch me:- Local Thread memory storage and synchronization

After so many years of successful relationship it was difficult to believe this unexpected behavior. So I started googling to get reasons for it.

After long hours of reading, I was stunned that there are two kinds of memory we have to deal when it comes to threading.

One is the main memory where our variables are allocated and the thread also has his own local memory…SURPRISED, same here.

In other words the “_loop” is present at three places one in the main memory and second in the local memories of “mainthread” and “somethread” functions.

When the program kick starts the “_loop” is set to true. So all the memory storages have “_loop” set to true. See the below visual representation.

As the program runs the main thread set the value to false. This updation is done in the local memory of “mainthread” and main the memory, but it does not update the local memory of “SomeThread”. So the “SomeThread” function still sees the stale value and keeps running in a loop.

Below is a visual representation of how things look internally at various points.

The unsung hero: - Volatile keyword

All relationships have problem, we just need to adjust, find solution and move with life. I was definitely in no mood of leaving c# threading after such a wonderful relationship.

The solution to get around this multiple memory storages was “VOLATILE” keyword.

If you declare your variable as volatile the thread tries to access values from main memory rather than from his local memory where data is stale. It does slow down a bit but it addresses this big confusion.

See it yourself, take the same source code and change the “_loop” variable to volatile as shown in the below code snippet and run it.

class Program
  volatile bool _loop = true;

Ensure that you select mode “release” and hit control + f5 to see the expected behavior.

Feel and See it yourself

In case you want to see it live what I have said in this blog see the video below

You can also see it yourself by downloading the code from the below link.

I am trainer by profession, interested in c# training , click here c# training .

Friday, May 18, 2012

UML Training: - Elaborate all types of diagrams in UML(Unified Modeling Language)?

There are nine types of diagrams in UML:-

Use case diagram:
They describe "WHAT" of a system rather than "HOW" the system does it. They are used to identify the primary elements and processes that form the system. The primary elements are termed as "actors" and the processes are called "use cases". Use Case diagrams shows "actors" and there "roles".

Class diagram:
From the use case diagram, we can now go to detail design of system, for which the primary step is class diagram. The best way to identify classes is to consider all "NOUNS" in use cases as classes, "VERBS" as methods of classes, relation between actors can then be used to define relation between classes. The relationship or association between the classes can be either an "is-a" or "has-a" relationship which can easily be identified from use cases.

Object diagram:
An object is an instance of a class. Object diagram captures the state of classes in the system and their relationships or associations at a specific point of time.

State diagram:
A state diagram, as the name suggests, represents the different states that objects in the system undergo during their life cycle. Object change in response to certain simulation so this simulation effect is captured in state diagram. Therefore, it has a initial state and final state and events that happen in between them. Whenever you think that some simulations are complicated, you can go for this diagram.

Sequence diagram:
Sequence diagrams can be used to explore the logic of a complex operation, function, or procedure. They are called sequence diagrams because sequential nature is shown via ordering of messages. First message starts at the top and the last message ends at bottom. The important aspect of a sequence diagram is that it is time-ordered. This means that the exact sequence of the interactions between the objects is represented step by step. Different objects in the sequence diagram interact with each other by passing "messages".

Collaboration diagram:
A collaboration diagram groups together the interactions between different objects to fulfill a common purpose.

Activity diagram:
Activity diagram is typically used for business process modeling, for modeling the logic captured by a single use case, or for visualizing the detailed logic of a business rule. Complicated process flows in the system are captured in the activity diagram. Similar to a state diagram, an activity diagram also consists of activities, actions, transitions, initial and final states, and guard conditions. However, difference is state diagrams are in context of simulation while activity gives detail view of business logic.

Deployment diagram:
Deployment diagrams show the hardware for your system, the software that is installed on that hardware, and the middleware used to connect the disparate machines to one another. It shows how the hardware and software work together to run a system. In one, line its shows the deployment view of the system.

Component diagram:
The component diagram represents the high-level parts that make up the system. From .NET angle point of view, they form the "NAMESPACES". This diagram depicts, at a high level, what components form part of the system, and how they are interrelated. Its shows the logical grouping of classes or group of other components.

See the following video on UML diagram: -

Click to get UML Training


Get more UML training stuffs from author's blog

Tuesday, May 15, 2012

C# Training: - Elaborate various types of IIS isolation levels?

IIS has three level of isolation:-

LOW (IIS process):- In this main IIS, process, and ASP.NET application run in same process. So if any one crashes the other is also affected. Example let us say (well this is not possible) I have hosted yahoo, hotmail .amazon and goggle on a single PC. So all application and the IIS process runs on the same process. In case any website crashes, it affects everyone.

Figure: - LOW IIS process scenario

Medium (Pooled):-
In Medium pooled scenario, the IIS, and web application run in different process. Therefore, in this case there are two processes process1 and process2. In process1, the IIS process is running and in process2, we have all Web application running.

Figure: - Medium pooled scenario

High (Isolated):-
In high isolated scenario every process is running is there own process. In below figure there are five processes and every one handling individual application. This consumes heavy memory but has highest reliability.

Figure: - High isolation scenario

See the following video on ASP.NET4.0 Redirectpermanent: -

Click to get C# Training


Get more C# training stuffs from author's blog

Thursday, May 3, 2012

ASP.Net Interview questions: - Mention differences between ‘Server.Transfer’ and ‘response.Redirect’?

Following are the major differences between them:-

‘Response. Redirect’ sends message to the browser saying it to move to some different page, while server. Transfer does not send any message to the browser but rather redirects the user directly from the server itself. So in ‘server. Transfer’ there is no round trip while ‘response. Redirect’ has a round trip and hence puts a load on server.

Using ‘Server. Transfer’ you cannot redirect to a different from the server itself. Example if your server is you cannot use server. Transfer to move to but yes, you can move to, i.e. with in websites. Cross server redirect is possible only by using Response. Redirect.

With ‘server. Transfer’ you can preserve your information. It has a parameter called as “preserveForm”.Therefore, the existing query string etc. will be able in the calling page.

If you are navigating within the same website use “Server. Transfer” or else go for “response.Redirect ()”

See the following video on ASP.NET4.0: -

Click for more ASP.NET interview questions


Visit for more Authors’ blog on ASP.NET interview questions

Wednesday, May 2, 2012

Strings are from earth and StringBuilder from mars.


I was happily married to string for a long time until I came to know the reality that “Strings are immutable” and not suitable for all scenarios. Recently I was working on a heavy HTML parser application and the program used to go out of memory frequently. The completely HTML parsing logic was using string variables.

After reading around I came to know the main reason was the immutable behavior of string. Immutable means once the data is assigned cannot be changed.

For instance if you are looping using a string variable like the code given below. Every assignment to the string creates new copies of variables and the previous copy is sent for garbage collection. So the below for loop generates different memory copies of data and the recently created is the current value.


Now you must be wondering why this absurd behavior. Any lame person (like me) can conclude this is not efficient and neither looks logical.

The sacrifice for thread safety

Before I start with the solution I wanted to understand why Microsoft team thought about this weird behavior. Thanks to things started looking logical.

If you are using string variables in multithreaded scenarios every thread modification will create new copy of memory ensuring that you do not land in to multi-threaded issues. In other words thread safety is built-in by itself when new copies of data are created.

Not all work on ships

The next thing which started itching me is what if my application is not multi-threaded. What if my main motive is to save memory resources and ensure that I do not go out of memory issues?. Here’s comes the hero from mars “StringBuilder”.

“Stringbuilder” are not immutable, in other words if you change the variable data the same memory location is modified. VOW, that looks lot of memory saving during heavy concatenation operation as compared to string.


I wanted to see for myself that earth is flat

As a curios developer it was difficult for me to digest that internally string creates different copies of data. Out of curiosity I downloaded the CLR Profiler and ran two test of code as shown below.

One for string as the below.

string x ="";

for (inti = 0; i< 10000; i++)
x = "Shiv"+ x;



One for string builder.

StringBuilder x = newStringBuilder();

for (inti = 0; i< 10000; i++)


Watch the allocated bytes, 400235631 bytes is way greaterthan 136597bytes.

Watch the video below for the real demo

If you do not believe what I have written see the actual video demo as follows

Saturday, April 21, 2012

ASP.NET interview questions: - How will you explain differences between ASP and ASP.NET?

This is the most practical oriented ASP.NET Interview Questions which may be asked during the Interview by the Interviewer.

ASP.NET new feature supports are as follows:-

Better Language Support
  • New ADO.NET Concepts have been implemented.
  • ASP.NET supports full language (C#, VB.NET, C++) and not simple scripting like VBSCRIPT...
Better controls than ASP
  • ASP.NET covers large set’s of HTML controls..
  • Better Display grid like Data grid, Repeater and datalist.Many of the display grid havpaging support.
Controls have events support
  • All ASP.NET controls support events.
  • Load, Click, and Change events handled by code makes coding much simpler and much better organized.
Compiled Code
ASP.NET supports forms-based user authentication, including cookie management and automatic redirecting of unauthorized logins. (You can still do your custom login page and custom user checking).

Better Authentication Support
ASP.NET supports forms-based user authentication, including cookie management and automatic redirecting of unauthorized logins. (You can still do your custom login page and custom user checking).

User Accounts and Roles
ASP.NET allows for user accounts and roles, to give each user (with a given role) access to different server code and executables.

High Scalability
  • Much has been done with ASP.NET to provide greater scalability.
  • Server to server communication has been greatly enhanced, making it possible to scale an application over several servers. One example of this is the ability to run XML parsers, XSL transformations, and even resource hungry session objects on other servers.
Easy Configuration
  • Configuration of ASP.NET is done with plain text files.
  • Configuration files can be uploaded or changed while the application is running. No need to restart the server. No more metabase or registry puzzle.
Easy Deployment
No more server restart to deploy or replace compiled code. ASP.NET simply redirects all new requests to the new code.

See the following video on ASP.NET for importance of session and view state: -

Click for more ASP.NET interview questions


Visit for more Authors’ blog on ASP.NET interview questions

Wednesday, April 18, 2012

ASP.NET interview questions: - Show in brief how the ASP.NET authentication process works?

ASP.NET does not run by itself, it runs inside the process of IIS. Therefore, there are two authentication layers, which exist in ASP.NET system. First authentication happens at the IIS level and then at the ASP.NET level depending on the WEB.CONFIG file.

Below is how the whole process works:-
  • IIS first checks to make sure the incoming request comes from an IP address that is allowed access to the domain. If not it denies the request.
  • Next IIS performs its own user authentication if it is configured to do so. By default IIS allows anonymous access, so requests are automatically authenticated, but you can change this default on a per – application basis with in IIS.
  • If the request is passed to ASP.NET with an authenticated user, checks to see whether impersonation is enabled. If impersonation is enabled, acts as though it were the authenticated user. If not acts with its own configured account.
  • Finally, the identity from step 3 is used to request resources from the operating system. If authentication can obtain all the necessary resources it grants the users request otherwise it is denied. Resources can include much more than just the page itself you can also use .NET’s code access security features to extend this authorization step to disk files, Registry keys and other resources.

See the following video on ASP.NET Forms authentication by using session hijack: -

Click for more ASP.NET interview questions


Visit for more Author's blog on ASP.NET interview questions

Saturday, April 14, 2012

ASP.NET interview questions: - Mention benefits and limitations of using Query Strings?

A simple but most frequently asked ASP.NET interview question.

A query string is information sent to the server appended to the end of a page URL.

Following are the benefits of using query string for state management:-
  • No server resources are required. The query string containing in the HTTP requests for a specific URL.
  • All browsers support query strings.
Following are limitations of query string:-
  • Query string data is directly visible to user thus leading to security problems.
  • Most browsers and client devices impose a 255-character limit on URL length.
See the following video on ASP.NET for importance of session and viewstate: -

Explore for more ASP.NET interview questions tutorials.


From Author’s blog see other blog links ASP.NET interview questions

Tuesday, April 10, 2012

ASP.NET Interview questions: - Mention use of session and viewstate in ASP.NET?

HTTP is a stateless protocol , session and viewstate help you to maintain states between request and response.

For more information see the below video.

Click for more ASP.NET Interview questions


Visit for more authors’ blog on ASP.NET Interview questions

Thursday, April 5, 2012

11 Important Database designing rules which I follow

Before you start reading this article let me confirm that I am not a guru in database designing. The below 11 points which are listed are points which I have learnt via projects, my own experiences and my own reading. I personally think it has helped me a lot when it comes to DB designing. Any criticism welcome.

The reason why I am writing a full blown article is, when developers sit for designing a database they tend to follow the three normal forms like a silver bullet. They tend to think normalization is the only way of designing. Due this mind set they sometimes hit road blocks as the project moves ahead.

In case you are new to normalization, then click and see 3 normal forms in action which explains all three normal forms step by step.

Said and done normalization rules are important guidelines but taking them as a mark on stone is calling for troubles. Below are my own 11 rules which I remember on the top head while doing DB design.

Courtesy: - Image from Motion pictures

Rule 1:- What is the Nature of the application(OLTP or OLAP)?
When you start your database design the first thing to analyze is what is the natureof theapplication you are designing for, is it Transactional or Analytical. You will find many developers by default applying normalization rules without thinking about the nature of the application and then later getting in to performance and customization issues. As said there are 2 kinds of applications transaction based and analytical based,let’s understand what these types are.

Transactional: - In this kind of application your end user is more interested in CRUD i.e. Creating, reading, updating and deleting records. The official name for such kind of database is called as OLTP.

Analytical: -In these kinds of applications your end user is more interested in Analysis, reporting, forecasting etc. These kinds of databases have less number of inserts and updates. The main intention here is to fetch and analyze data as fast as possible. The official name for such kind of databases is OLAP.

So in other words if you think insert, updates and deletes are more prominent then go for normalized table design or else create a flat denormalized database structure.

Below is a simple diagram which shows how the names and address in the left hand side is a simple normalized table and by applying denormalized structure how we have created a flat table structure.

Rule 2:- Break your data in to logical pieces, make life simpler
This rule is actually the 1st rule from 1st normal formal. One of the signs of violation of this rule is if your queries are using too many string parsing functions like substring, charindexetc , probably this rule needs to be applied.

For instance you can see the below table which has student names , if you ever want to query student name who is having “Koirala” and not “Harisingh” , you can imagine what kind of query you can end up with.

So the better approach would be to break this field in to further logical pieces so that we can write clean and optimal queries.

Rule 3:- Do not get overdosed with rule 2
Developers are cute creatures. If you tell them this is the way, they keep doing it; well they overdo it leading to unwanted consequences. This also applies to rule 2 which we just talked above. When you think about decomposing, give a pause and ask yourself is it needed. As said the decomposition should be logical.

For instance you can see the phone number field; it’s rare that you will operate on ISD codes of phone number separately(Until your application demands it). So it would be wise decision to just leave it as it can lead to more complications.

Rule 4:- Treat duplicate non-uniform data as your biggest enemy
Focus and refactor duplicate data. My personal worry about duplicate data is not that it takes hard disk space, but the confusion it creates.

For instance in the below diagram you can see “5th Standard” and “Fifth standard” means the same. Now you can say due to bad data entry or poor validation the data has come in to your system. Now if you ever want toderive a report they would show them as different entities which is very confusing from end user point of view.

One of the solutions would be to move the data in to a different master table altogether and refer then via foreign keys. You can see in the below figure how we have created a new master table called as “Standards” and linked the same using a simple foreign key.

Rule 5:- Watch for data separated by separators.
The second rule of 1st normal form says avoid repeating groups. One of the examples of repeating groups is explained in the below diagram. If you see the syllabus field closely, in one field we have too much data stuffed.These kinds of fields are termed as “Repeating groups”. If we have to manipulate this data, the query would be complex and also I doubt performance of the queries.

These kinds of columns which have data stuffed with separator’s need special attention and a better approach would be to move that field to a different table and link the same with keys for better management.

So now let’s apply the second rule of 1st normal form “Avoid repeating groups”. You can see in the above figure I have created a separate syllabus table and then made a many-to-many relationship with the subject table.

With this approach the syllabus field in the main table is no more repeating and having data separators.

Rule 6:- Watch for partial dependencies.

Watch for fields which are depending partially on primary keys. For instance in the above table we can see primary key is created on roll number and standard. Now watch the syllabus field closely. Syllabus field is associated with a standard and not with a student directly (roll number).

Syllabus is associated with the standard in which the student is studying and not directly with the student. So if tomorrow we want to update syllabus we have to update for each student which is pain staking and not logical. It makes more sense to move these fields out and associate them with the standard table.

You can see how we have move the syllabus field and attached the same to standards table.

This rule is nothing but second normal form “All keys should depend on the full primary key and not partially”.

Rule 7:- Choose derived columns preciously

If you are working on OLTP applications must be getting rid of derive columns would be good thought, until there is some pressing reason of performance. In case of OLAP where we do lot of summations, calculations these kinds of fields are necessary to gain performance.

In the above figure you can see how average field is dependent on marks and subject. This is also one of form of redundancy. So for such kind of fields which are derived from other fields give a thought are they really necessary.

This rule is also termed as 3rd normal form “No columns should depend on other non-primary key columns”. My personal thought is do not apply this rule blindly see the situation; it’s not that redundant data is always bad. If the redundant data is calculative data , see the situation and then decide do you want to implement the third normal form.

Rule 8:- Do not be hard on avoidingredundancy, if performance is the key

Do not make it a strict rule that you will always avoid redundancy. If there is a pressing need of performance think about de-normalization. In normalization you need to make joins with many table and in denormalization the joins reduces and thus increasing performance.

Rule 9:- Multidimensional data is a different beast altogether
OLAP projects mostly deal with multidimensional data. For instance you can see the below figure, you would like to get sales as per country, customer and date. In simple words you are looking at sales figure which have 3 intersections of dimension data.

For such kind of situations a dimension and fact design is a better approach. In simple words you can create a simple central sales fact table which has the sales amount field and he makes a connection with all dimension tables using a foreign key relationship.

Rule 10:- Centralize name value table design
Many times I have come across name value tables. Name and value tables means it has key and some data associated with the key. For instance in the below figure you can see we have currency table and country table. If you watch the data closely they actually only have Key and value.

For such kind of table creating one central table and differentiating the data by using a type field makes more sense.

Rule 11:- For unlimited hierarchical data self-reference PK and FK
Many times we come across data with unlimited parent child hierarchy. For instance consider a Multi-level marketing scenario where one sales person can have multiple sales people below them. For such kind of scenarios using a self-referencing primary key and foreign key will help to achieve the same.

This article is not meant to say that do not follow normal forms , but do not follow them blindly , look at your project nature and type of data you are dealing with.

Out of full respect, below is a video which explains 3 normal forms step by step using a simple school table.

You can also visit my site for step by step videos on Design Patterns, UML, SharePoint 2010, .NET Fundamentals, VSTS, UML, SQL Server, MVC and lot more.

Visit for more authors blog on .NET Interview questions