What will be the error,if we Compile below function in C# application?

private void sum(int a, int b)
return a + b;
catch (Exception ex)
throw ex;

 Posted by vishalneeraj-24503 on 11/28/2013 | Category: C# Interview questions | Views: 2594 | Points: 40

It will throw an error at Compile-time saying that:-

"Since '_Default.sum(int, int)' returns void, a return keyword must not be followed by an object expression".

So meaning that,if we are creating any function,that returns void means void does not return anything.So we must not return any value from inside function or method.

So we have to remove "return a + b;" from above function.

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response