Monday, 21 January 2013

Tricky Asp.net interview Question

 Hi friends,

In the last month I had given one interview in one of the large MNC in Pune.
In that interview, one interviewer asked me one questions about Try Catch block in asp.net.
I liked that questions and really it’s challenging question.

Scenario 1 :-

Please find following Code and trace the output


Try{
Response,redirect("1.aspx");
}

Catch{
Response,redirect("2.aspx");
}

finally{
Response,redirect("3.aspx");
}

Answer:

The Output of this one is that it will redirect the page to 3.aspx as on try block this will throw a redirect error but after catch block the control will go to the finally block which will redirect the page to 3.aspx..





Scenario 2

Trace the output



Try
{
Server.Transfer("1.aspx");
}

Catch
{
Server.Transfer("2.aspx");
}

finally
{
Server.Transfer("3.aspx");
}

Answer:

In the Second case we are using Server.Transfer which will directly transfer the current page to show the contents of the page to be redirected keeping the url address as the same.. IN this case it will move through all three blocks and would show the contents of 1.aspx, 2.aspx and 3.aspx from the main page... ie., if we are transferring from main.aspx then it will show the contents of 1.aspx plus the content of 2.aspx and the content of 3.aspx in main.aspx..





Happy Programming!!

Don’t forget to leave your feedback and comments below!

If you have any query mail me to Sujeet.bhujbal@gmail.com     


Regards

Sujeet Bhujbal
--------------------------------------------------------------------------------
-----------------------------------------------------------------------------------


14 comments :

Anil Singh said...

Its very cool code hmm

Sujit Bhujbal said...

Thanks Anil

Anonymous said...

thanks buddy really interesting......

Unknown said...

Really tricky question.and good for interview preparation

Mahesh said...

Thanks for sharing Sujit

ashitha viswanath said...

thank u...Expecting more questions like this

Maky said...

Faltu Question Yaar

Maky said...

Tu khudko kya shivprasad samjhta hai kya

Sujit Bhujbal said...

Thanks all my friends

Anonymous said...

hey sujit do you plz upload more tricky programs

VrundaaS said...

Wow.. Its Great!!! Please post more tricky questions.. Thanks...

Anonymous said...

Really interesting !!!
sometimes we go on coading....but miss these magic tricks of our favourite C#..
Thanks for sharing ....

ganesh pate said...

Nice one

Kiran Shetty said...

in 1st Question i think.. there is Syntactic error:
Response,redirect("1.aspx");

it should be Response.redirect("1.aspx"); -i guess.

Please comment

Post a Comment