[Solved] not all code paths return a value. In C#


Your problem is that you don’t return any value at the end of your method. You can re write your method like this. It is more understandable and should fill your reqirments.

public bool CanJoyride(int age, int cm, bool hasHeartCondition)
{
    if (hasHeartCondition)        
        return false;


    if(age >= 18 && cm >= 130 && cm <= 210)
        return true;


     if (age >= 12 && cm >= 150 && cm <= 210)
        return true;

     return false;         
}

You should avoid writing code in arrow way. That means avoid nested if, because the code become unreadable and hard to follow.

solved not all code paths return a value. In C#