OverflowException:在VB中长到ULong,但在C#中长 [英] OverflowException: Long to ULong in VB but not in C#

查看:102
本文介绍了OverflowException:在VB中长到ULong,但在C#中长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试将long值:-279691878727680转换为无符号的long值.在C#中,我收到:18446464381830823936,但是在vb中,我收到了算术溢出异常. :confused:

有人可以吗?解释为什么两种环境之间存在差异,如何解决该问题?所使用的框架都适用于2.0(VS 2008).

谢谢


丹尼尔.

Hi,

I am trying to convert the long value: -279691878727680 to an unsigned long value. In C# I receive: 18446464381830823936 but in vb I am getting an arithmetic overflow exception. :confused:

Can someone pls. explain why there are differences between both environments and how can I solve that issue? The used framework is for both 2.0 (VS 2008).

Thank you,


Daniel.

推荐答案



我可以通过在项目属性中禁用整数溢出检查来解决此问题.但是我想这不是最佳"解决方案...
问候,


Daniel.
Hi,

I could resolve it by disabling of integer overflow checks within the project properties. But I guess this is not the "finest" solution ...
Regards,


Daniel.


VB:
If (CULng(val) And &HFFFF000000000000UL) = &HFFFF000000000000UL



C#:



C#:

if (((ulong)val & 0xFFFF000000000000) == 0xFFFF000000000000)



我的猜测是那些不会产生相同的IL.我不知道VB.NET语法,但是有没有一种方法可以像C#中那样直接进行直接转换?使用CULng(...)可能是经过优化的VB特定调用,其导致的IL与您进行直接强制转换时所生成的IL不同(假定VB语法支持).



My guess is that those don''t produce identical IL. I don''t know VB.NET syntax, but is there a way you can actually do a direct cast, like in C#? Using CULng(...) may be an optimized VB specific call that results in IL that''s different from what''d be generated if you do a direct cast (assuming VB syntax supports that).


这篇关于OverflowException:在VB中长到ULong,但在C#中长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆