Error reported for explicit conversion from native integer to enum
See original GitHub issueExplicit conversions should be allowed from native integers to enum values.
enum E { }
class Program
{
static void Main()
{
nint i = 1;
nuint u = 2;
E e;
e = (E)i;
e = (E)u;
}
}
Expected: No errors
Result:
(10,13): error CS0030: Cannot convert type 'nint' to 'E'
(11,13): error CS0030: Cannot convert type 'nuint' to 'E'
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Implicit conversion from int to enum class in switch statement
Incidentally, simple assignment without explicit cast such as pid a = propId; gives error in each compiler. Which one got it right? c++...
Read more >Type conversion: Enum data types and integer
The enumeration to integer conversion operator converts the given enum operand to a signed or unsigned integer data type. In practice, the conversion...
Read more >How to Handle the Incompatible Types Error in Java
The incompatible types error most often occurs when manual or explicit conversion between types is required, but it can also happen by ...
Read more >Enum Classes in C++ and Their Advantage over ...
Class enum doesn't allow implicit conversion to int, and also doesn't compare enumerators from different enumerations. To define enum class ...
Read more >Enumeration (or enum) in C
A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Good to know!
Consider also the implicit enumeration conversion case:
Thanks @Youssef1313. I’m already working on a fix.