Division in VB.NET

前端 未结 4 1913
隐瞒了意图╮
隐瞒了意图╮ 2021-01-01 19:13

What\'s the difference between / and \\ for division in VB.NET?

My code gives very different answers depending on which I use. I\'ve seen b

4条回答
  •  醉梦人生
    2021-01-01 19:33

    10 / 3 = 3.33333333333333, assigned to integer = 3
    10 \ 3 = 3, assigned to integer = 3
    20 / 3 = 6.66666666666667, assigned to integer = 7
    20 \ 3 = 6, assigned to integer = 6
    

    Code for the above:

    Dim a, b, c, d As Integer
    a = 10 / 3
    b = 10 \ 3
    c = 20 / 3
    d = 20 \ 3
    
    Debug.WriteLine("10 / 3 = " & 10 / 3 & ", assigned to integer = " & a)
    Debug.WriteLine("10 \ 3 = " & 10 \ 3 & ", assigned to integer = " & b)
    Debug.WriteLine("20 / 3 = " & 20 / 3 & ", assigned to integer = " & c)
    Debug.WriteLine("20 \ 3 = " & 20 \ 3 & ", assigned to integer = " & d)
    

提交回复
热议问题