I\'m new to programming and having a problem with the following code:
private string alphaCoords(Int32 x)
{
char alphaChar;
switch (
You are assigning value to the variable alphaChar based on some condition. Imagine a scenario where the variable x contains value other than 0 to 9. Suppose it contains 10. Then none of the case conditions will be satisfied by x, so alphaChar will not be assigned any value, as a result it will be totally uninitialized. So when you are converting alphaChar to string, it is converting some garbage value to string and returning it to the calling method. This is the reason why you are getting that message.
If you want to get a simple solution, then add the following code below
case 9: alphaChar = 'J';
break;
-
default: return null;
and check in the calling methods whether this alphaCoords function returns null or not, like this -
if(alphaCooord(10) == null)
{
// x contains value other than 0 to 9
}
else
{
// x contains value between 0 to 9, so the returned value will be the string
// representation of the corresponding character
}
In this way your code won't be too complex, or you won't need to throw or handle any exceptions or something like that.
Hope that helps :).