Why does the first and second Write work but not the last? Is there a way I can allow all 3 of them and detect if it was 1, (int)1 or i passed in? And really why is one allo
There is no implicit conversion from int
to short
because of the possibility of truncation. However, a constant expression can be treated as being of the target type by the compiler.
1
? Not a problem: it’s clearly a valid short
value. i
? Not so much – it could be some value > short.MaxValue
for instance, and the compiler cannot check that in the general case.