Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integer Overflow - Converting C# to VB.Net code

Got a problem with a code conversion from C# to VB.Net.

var x = 5783615;
var y = 56811584;
var t = x * y;

x, y and t are integers. In c# 't' will be -1553649728. In VB.Net, I will get an integer overflow exception.

Any idea how to fix it?

like image 946
user1717864 Avatar asked Apr 23 '26 18:04

user1717864


1 Answers

C#, by default, doesn't check for overflows, but VB does (by default).

You can setup your VB Project to not check for integer overflows in the Advanced Compile Options in the Compile tab. This will cause that specific project to stop raising OverflowException in cases like this.

like image 76
Reed Copsey Avatar answered Apr 26 '26 07:04

Reed Copsey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!