Cannot use local variable before it is declared
In visual studio. Sometimes when you declare a variable again (a second time). It will give this error. For example, this will sometimes throw the exception you mentioned:
1. int startingRadius = 0;
2. startingRadius = 5; <-- Exception thrown here.
3.
4. int startingRadius = 0;
Obviously this is incorrect anyway. So removing the second declaration (on line 4) will solve the problem.
Note: The exception you would ordinarily expect would be A local variable named 'startingRadius' is already defined in this scope
. But for some reason, the exception you mentioned is shown sometimes.
You are missing a closing brace for your method but otherwise this code can compile on my machine... (changed Height to a property as well)
public int[] genericSearch(int searchWidth, int startingRadius, int width, int height,Bitmap bitmap)
{
//Generic function for finding the best path from a certain range
if (startingRadius == -1)
startingRadius = bitmap.Height / 2;
}