快速检查一个数字是否可以被另一个数字整除?

pim*_*vdb 7 vb.net integer numbers division

我想知道在VB.NET中检查可分性的最快方法是什么.

我尝试了以下两个功能,但我觉得好像有更有效的技术.

Function isDivisible(x As Integer, d As Integer) As Boolean
     Return Math.floor(x / d) = x / d
End Function
Run Code Online (Sandbox Code Playgroud)

我提出的另一个:

Function isDivisible(x As Integer, d As Integer) As Boolean
     Dim v = x / d
     Dim w As Integer = v
     Return v = w
End Function
Run Code Online (Sandbox Code Playgroud)

这是一种更实用的方法吗?

gor*_*gor 32

用途Mod:

Function isDivisible(x As Integer, d As Integer) As Boolean
    Return (x Mod d) = 0
End Function
Run Code Online (Sandbox Code Playgroud)


Mat*_*t F 7

使用'Mod'返回number1的余数除以number2.因此,如果余数为零,则number1可被number2整除.

例如

昏暗的结果As Integer = 10 Mod 5'result = 0