如何在不未经检查的情况下做到这一点?
几个月前,我编写了这段代码,因为这是我能想到的唯一方法(在学习 C# 时)。你会怎么做? unchecked
是执行此操作的正确方法吗?
unchecked //FromArgb takes a 32 bit value, though says it's signed. Which colors shouldn't be.
{
_EditControl.BackColor = System.Drawing.Color.FromArgb((int)0xFFCCCCCC);
}
a few months ago I wrote this code because it was the only way I could think to do it(while learning C#), well. How would you do it? Is unchecked
the proper way of doing this?
unchecked //FromArgb takes a 32 bit value, though says it's signed. Which colors shouldn't be.
{
_EditControl.BackColor = System.Drawing.Color.FromArgb((int)0xFFCCCCCC);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它需要一个有符号的 int b/c,这可以追溯到 VB.NET 没有无符号值的时候。因此,为了保持 C# 和 VB.NET 之间的兼容性,所有 BCL 库都使用有符号值,即使它没有逻辑意义。
It takes a signed int b/c this dates back to the time when VB.NET didn't have unsigned values. So in order to maintain compatibility between C# and VB.NET, all the BCL libraries utilize signed values, even if it does not make logical sense.
您可以分解 int 的各个组成部分,并使用
FromArgb()
重载将它们分开:You could break down the components of the int and use the
FromArgb()
overload that takes them separately:扩展方法可以隐藏这一点:
用法:
似乎它们应该是另一种符号(如 0v12345678)或其他一些方法来解决此问题。
Extension methods can hide this:
Usage:
Seems like they're should be another notation (like 0v12345678) or some other way to work around this issue.