Using C#; I just realized, declaring noValueNumber
as const int
and returning it from this short
function.
Why there is not an error message, like:
Can't convert exxpression type
int
to return typeshort
public static short ValueFromString(string onlyNumbersString)
{
if (onlyNumbersString.Length == 0)
{
const int noValueNumber = 999;
return noValueNumber; // ¿...?
}
return Int16.Parse(onlyNumbersString);
}
Shouldn't be necessary a cast?, or there is, but hidden?
MSDN mentions that:
A (constant) value that fits
short
though is OK with implicit conversion.Edit: Found the proper (positive) documentation for your example, Implicit Numeric Conversions Table (C# Reference), that states that: