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

LJ9999 picture LJ9999  Â·  3Comments

ygoe picture ygoe  Â·  3Comments

Manoj-Prabhakaran picture Manoj-Prabhakaran  Â·  3Comments

svick picture svick  Â·  3Comments

ite-klass picture ite-klass  Â·  3Comments