VB.Net Tutorial/Data Type/Cast

Материал из VB Эксперт
Перейти к: навигация, поиск

Implicit casting of quotient to an integer

Option Strict Off
 " must be off to allow implicit casting of quotient to an integer
 Imports System
 Module Module1
    Sub Main( )
       Dim twelve As Integer = 12
       Dim five As Integer = 5
       Dim intAnswer As Integer
       Dim doubleAnswer As Double
       Console.WriteLine("{0} + {1} = {2}",twelve, five, twelve + five)
       Console.WriteLine("{0} - {1} = {2}",twelve, five, twelve - five)
       Console.WriteLine("{0} * {1} = {2}",twelve, five, twelve * five)
       " integer division
       intAnswer = twelve \ five
       doubleAnswer = twelve \ five
       Console.WriteLine("{0} \ {1} = [integer] {2}  [double] {3}", _
           twelve, five, intAnswer, doubleAnswer)
       " division. Assign result to both an integer and a double
       " note, option strict must be off!
       intAnswer = twelve / five
       doubleAnswer = twelve / five
       Console.WriteLine("{0} / {1} = [integer] {2}  [double] {3}", _
           twelve, five, intAnswer, doubleAnswer)
    End Sub
 End Module
12 + 5 = 17
12 - 5 = 7
12 * 5 = 60
12 \ 5 = [integer] 2  [double] 2
12 / 5 = [integer] 2  [double] 2.4