The following code will generate a compiler error.
string GetAgePhrase(int age)
{
if (age > 50) return "Naresh";
if (age > 30) return "Ravi";
if (age > 10) return "Nagendra";
if (age > 9) return "Jagan";
if (age > 2) return "Raja";
}
Which of the following statements, inserted as the last line of the
function, would solve the problem?
The problem with this code is that not all paths of the code return a value… i.e. what if age is 0? You can fix this by adding after the last if statement
return nullthis way if none of the conditions are met it will always have a return value.