Implicit cast from int to byte in C# [closed]
So I was writing some C# code today and I was rather surprised when I got the error: "Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?)". I read around a bit and apparently, this is not possible without an explicit conversion.
I call bullshit on that. I have been working for weeks with a C# project where this conversion is happening all over the place without any errors. So, my question is, where do you change this behavior? It's obviously possible.
No, you can't. You can implicitly cast a byte
to an int
without any written cast, but not the other way since an int
can be a number that overflows a byte
.
精彩评论