Replies: 1 comment 6 replies
-
The result type of the non-const conditional expression But you can write: using System;
bool foo = false;
uint z = foo ? 1u : 2; which changes the result type to If you change your code to: const bool foo = false;
uint z = foo ? 1 : 2; Than implicit constant conversion would apply here, too. |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I hope this isn't covered somewhere else, but if so please feel free to close this with a duplicate reference.
I found that the following simple code won't compile:
The same is true for switch expressions:
The error is that an int can't be implicitly converted to uint. I understand that in general but here it is very clear that in any case the value is a valid uint.
Is this not possible to allow for some reason? I know I can use casts or literal suffixes like
1u
. But I would prefer to avoid that as in some cases a type might change later and it should work without it imo. And suffixes won't work for smaller types likebyte
.The same is true for any other integer type like
byte
etc which has no implicit conversation from int. So typelong
will work of course for obvious reasons.Beta Was this translation helpful? Give feedback.
All reactions