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

guardrex picture guardrex  Â·  51Comments

SidShetye picture SidShetye  Â·  24Comments

richlander picture richlander  Â·  23Comments

BillWagner picture BillWagner  Â·  36Comments

mohag picture mohag  Â·  47Comments