What will happen,when we compile below C# code?
private int Calculate(int a, int b)
{
int i = a;
int j = b;
int k = i + j;
}

 Posted by vishalneeraj-24503 on 10/8/2014 | Category: C# Interview questions | Views: 2485 | Points: 40
Answer:

'_Default.Calculate(int,int)': not all code paths return a value
Above error means if we have defined any method with return type then we have to explicitly return that type otherwise it will not compile and will throw above error.So we have to re-write below code as:-
private int Calculate(int a, int b)

{
int i = a;
int j = b;
int k = i + j;
return k;
}


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response