Can we use goto statement in the finally block?

 Posted by Ddd on 2/15/2011 | Category: C# Interview questions | Views: 3062 | Points: 40
Answer:

Yes, we can use the goto statement in the finally block.

Code snippet:

class abc

{
static void Main()
{
try
{
Console.WriteLine("welcome");

}

finally
{
goto dd;

dd:
Console.WriteLine("last");
}
}
}


//This block of code will execute since the label dd is inside the finally block.
//if the label dd was outside the finally block, the compiler would have generate
//the error--cannot leave the body of finally clause


| Alert Moderator 

Comments or Responses

Login to post response