开发者

Implicit cast from int to byte in C# [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_开发问答 Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜