is there some way of return null if it can\'t parse a string to int?
with:
public .... , string? categoryID)
{
int.TryParse(categoryID, out categoryID);
TryParse
will return false if the string can't be parsed. You can use this fact to return either the parsed value, or null. Anyway I guess that you are intending to return int?
from your method, then it would be something like this:
public int? ParseInt(string categoryID)
{
int theIntValue;
bool parseOk = int.TryParse(categoryID, out theIntValue);
if(parseOk) {
return theIntValue;
} else {
return null;
}
}