Re: Method returns value error



Perhaps, but the _compiler_ doesn't know that. It looks at the method
in isolation. It sees that there is a path through the method for which
the retFinalPercentage variable doesn't get set, so it complains.

It's always good to put error handling in your code, even in those
"this can never happen" case. The impossible happens once in a while,
trust me.

So, if the caller can't possibly pass a value not in the array, that
leaves you with something like this:

public static double SelectFinalPercent2(int imyFuture)
{
int[] aAge = {55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65};
double[] aPercent = {.37, .40, .43, .49, .55, .61, .67, .73, .82,
..91, 1.0};

for(int x = 0; x < aAge.Length; ++x)
{
if(imyFuture == aAge[x])
{
return aPercent[x];
}
}
throw new ArgumentException(String.Format("{0} is not a valid
age.", imyFuture), "imyFuture");
}

Joseph wrote:
A better reply to your question is that the user is only limiter to the ones
listed in int[] aAge. The passing parameter will always be ones listed. I
have the necessary error providers in place to insure that.

.