I am trying to find out where the issue is in this code and I just can't find it. beginning of statement....
private Units unitsToUse;
private int[] dataCaptured = new int[30];
private int mostRecentMeasure;
method at end of statement....
public int Measure(int v, Units u)
{
if (v != 0 && v != null)
{
mostRecentMeasure = v;
if (u == Units.Metric)
{
unitsToUse = u;
for (int i = 0; i < 30; i++)
{
if (dataCaptured[i] != 0 && dataCaptured[i] != null && i < 29)
{
continue;
}
if (i == 29 && dataCaptured[i] != null)
{
i = 0;
dataCaptured[i] = mostRecentMeasure;
return mostRecentMeasure;
}
dataCaptured[i] = mostRecentMeasure;
return mostRecentMeasure;
}
}
else if (u == Units.Imperial)
{
unitsToUse = u;
for (int i = 0; i < 30; i++)
{
if (dataCaptured[i] != 0 && dataCaptured[i] != null && i < 29)
{
continue;
}
if (i == 29 && dataCaptured[i] != null)
{
i = 0;
dataCaptured[i] = mostRecentMeasure;
return mostRecentMeasure;
}
dataCaptured[i] = mostRecentMeasure;
return mostRecentMeasure;
}
}
else
{
throw new ArgumentOutOfRangeException("Your units were neither of the available values.");
}
}
else
{
throw new ArgumentOutOfRangeException("Your value of measuring was not in the specified range.");
}
}
Now The method is going to receive a valid Enum value for Units and a valid value from the int V through a random 1-10 method elsewhere in the code. What i don't understand is where the code isn't returning a value or throwing an exception to handle any erroneous cases of the method executing outside of the parameters. I've been stuck here for a while and any help would be appreciated.