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
--------------------------------------------------------------------------------
-----------------------------------------------------------------------------------


15 comments:

  1. thanks buddy really interesting......

    ReplyDelete
  2. Really tricky question.and good for interview preparation

    ReplyDelete
  3. Thanks for sharing Sujit

    ReplyDelete
  4. thank u...Expecting more questions like this

    ReplyDelete
  5. Tu khudko kya shivprasad samjhta hai kya

    ReplyDelete
  6. hey sujit do you plz upload more tricky programs

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

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

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

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

    Please comment

    ReplyDelete
  10. Blog is very appreciable for its content part helped me lot in career assessment and got one of the Delhi metro job vacancy for 12th pass according to my profile on Job vacancy result with 100% job assistance in some easy steps

    ReplyDelete
  11. Respect and that i have a super give: How Much Home Renovation Cost my home renovation

    ReplyDelete