E
estafford
Newbie looking for some insight here.
I am writing a block to check limitations on a query string as follows:
public bool validNumber(string qstring){
bool isValidNumber;
foreach(char c in qstring){
if(!Char.IsNumber(c)){
isValidNumber = false;
break;
}
else{isValidNumber = true;}
}
return isValidNumber;
}
This however returns a compiler error: - CS0165: Use of unassigned local
variable 'isValidNumber' - at the "return isValidNumber" line.
But if I move the second line [isValidNumber decleration] outside of the
function, it works fine.
Why does this happen if I am only using the variable within the function?
And if anyone has an easier way of checking a number only value, I'd sure
like to know.
Thanks for any help with this.
I am writing a block to check limitations on a query string as follows:
public bool validNumber(string qstring){
bool isValidNumber;
foreach(char c in qstring){
if(!Char.IsNumber(c)){
isValidNumber = false;
break;
}
else{isValidNumber = true;}
}
return isValidNumber;
}
This however returns a compiler error: - CS0165: Use of unassigned local
variable 'isValidNumber' - at the "return isValidNumber" line.
But if I move the second line [isValidNumber decleration] outside of the
function, it works fine.
Why does this happen if I am only using the variable within the function?
And if anyone has an easier way of checking a number only value, I'd sure
like to know.
Thanks for any help with this.