hi everyone!!!!
I have written a function that shud return a decimal value.But I'm getting an error in c#.net(windows Application) which is a build error--->not all code paths return a value.Can anyone plzz suggest why this error is popping up.What does this mean???
Thnks in advance
siri
do you have a return statement?
make sure you have one return statement in the method
the followinf method will give the error you are reciving
- private decimal myMethod()
-
{
-
decimal i,j;
-
i = 10;
-
j = 20;
-
if(i + j > 100)
-
{
-
return i + j;
-
}
-
}
You should be doing something similar to
- private decimal myMethod()
-
{
-
decimal i,j;
-
i = 10;
-
j = 20;
-
if(i + j > 100)
-
{
-
return i + j;
-
}
-
return 0;
-
}
returning values in between is something which i consider to be not so good programming at times (though i still use it because it saves time, along with some other factors)
the suggested implementation whould be
- private decimal myMethod()
-
{
-
decimal i,j;
-
i = 10;
-
j = 20;
-
decimal result = i + j;
-
if(result > 100)
-
{
-
//do nothing
-
}
-
else
-
result = 0;
-
return result;
-
}