Docs: Cannot convert int to short

Created on 4 Oct 2018  Â·  1Comment  Â·  Source: dotnet/docs

why the below line is not compiled
short x = condition ? 0 : 1;
and I have to cast it
short x = (short) (condition ? 0 : 1);


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Area - C# Guide doc-provided

Most helpful comment

@taha3azab

That's because integral numeric literals are of type int. That's detailed in the C# spec on integer literals

Closing this.

>All comments

@taha3azab

That's because integral numeric literals are of type int. That's detailed in the C# spec on integer literals

Closing this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ike86 picture ike86  Â·  3Comments

mekomlusa picture mekomlusa  Â·  3Comments

tswett picture tswett  Â·  3Comments

sime3000 picture sime3000  Â·  3Comments

stjepan picture stjepan  Â·  3Comments