In C# all functions must return a value through all possible code paths.
static int SumNum(int num)
{
for (int i = 0; i <= num; i++)
{
return i;
}
}
Notice in your function, once indented, that you are not returning a value from the function if num is less than 0. The for loop will never execute the statement inside it and therefore code continues after the loop. Since there is no return then the compiler fails. To fix that return a value for when num is less than 0.
Also note that your code isn't actually summing up anything. It is returning the first time through the loop so the result will always be 0. You should create an accumulator local variable. Each time through the loop add the current loop value (i) to the local variable. Once the loop is complete then return the accumulated value. Interestingly, this would resolve the compiler error as well since you would initialize your accumulator to 0.