Imports System
Class OverflowCheck
Public Shared Function AddingWillOverflow(ByVal x As Integer, ByVal y As Integer) As Boolean
Return ((x > 0) AndAlso (y > Integer.MaxValue - x)) OrElse ((x < 0) AndAlso (y < Integer.MinValue - x))
End Function
Public Shared Sub Main()
Dim x As Integer = 39839299, y As Integer = 1472783642
Console.WriteLine(If(AddingWillOverflow(x, y), "true", "false"))
x = 1338839299
y = 1872783642
Console.WriteLine(If(AddingWillOverflow(x, y), "true", "false"))
End Sub
End Class
' run:
'
' false
' true
'