Sunday, August 16, 2015

Can we write Return statement in finally block in c#?

Return statement in finally block

No. we can not write Return statement in finally block in c#. if you will write it, application will give you compilation error.

Example:

try
{
Return 1;
}
Catch(Exception ex)
{
Return 2;
}
Finally
{
Return 3; // Compilation error
}


It will give you compilation error as you cannot write “Return” statement in finally block.

No comments:

Post a Comment