VB.Net/Language Basics/Integer

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

And, Or, Xor and Not on Integer

Imports System
Public Class MainClass
    Shared Sub Main(ByVal args As String())
       Dim x As Integer = 5
       Dim y As Integer = 7
       Dim andValue As Boolean
       Dim orValue As Boolean
       Dim xorValue As Boolean
       Dim notValue As Boolean
       andValue = x = 3 And y = 7
       orValue = x = 3 Or y = 7
       xorValue = x = 3 Xor y = 7
       notValue = Not x = 3
       Console.WriteLine("x = 3 And y = 7. {0}", andValue)
       Console.WriteLine("x = 3 Or y = 7. {0}", orValue)
       Console.WriteLine("x = 3 Xor y = 7. {0}", xorValue)
       Console.WriteLine("Not x = 3. {0}", notValue)
    End Sub
End Class


Compare Integer value and output their relation

Imports System
public class MainClass
    Shared Sub Main()
       Dim valueOne As Integer = 10
       Dim valueTwo As Integer = 20
       Dim valueThree As Integer = 30
       Console.WriteLine("Testing valueOne against valueTwo...")
       If valueOne > valueTwo Then
          Console.WriteLine( _
              "ValueOne: {0} larger than ValueTwo: {1}", _
               valueOne, valueTwo)
       End If
       Console.WriteLine("Testing valueThree against valueTwo...")
       If valueThree > valueTwo Then
          Console.WriteLine( _
              "ValueThree: {0} larger than ValueTwo: {1}", _
               valueThree, valueTwo)
       End If
       Console.WriteLine("Testing is valueTwo > 15 (one line)...")
       If valueTwo > 15 Then Console.WriteLine("Yes it is")
    End Sub
End Class


Concatenate string and int

Imports System
Public Class MainClass
    Shared Sub Main()
        "Declare variable
        Dim intNumber As Integer
        "Set the value
        intNumber = 26
        "Display the results
        System.Console.WriteLine("The value of intNumber is: " & intNumber)
    End Sub
End Class


Define and use Array Integer

Imports System

Public Class MainClass
    
    Shared Sub Main(ByVal args As String())
        Dim squares(10) As Integer
        For i As Integer = 0 To 10
            squares(i) = i * i
        Next i
        Dim txt As String = ""
        For i As Integer = 0 To 10
            Console.WriteLine (squares(i).ToString )
        Next i
    End Sub
End Class


Integer: add, subtract, multiply and divide

Imports System
Public Class MainClass
    Shared Sub Main()
        "Declare variable
        Dim intNumber As Integer
        "Set number, add numbers, and display results
        intNumber = 16
        "intNumber = intNumber + 8
        intNumber += 8
        System.Console.WriteLine("Addition test... " & intNumber)
        "Set number, subtract numbers, and display results
        intNumber = 24
        "intNumber = intNumber - 2
        intNumber -= 2
        System.Console.WriteLine("Subtraction test... " & intNumber)
        "Set number, multiply numbers, and display results
        intNumber = 6
        "intNumber = intNumber * 10
        intNumber *= 10
        System.Console.WriteLine("Multiplication test... " & intNumber)
        "Set number, divide numbers, and display results
        intNumber = 12
        "intNumber = intNumber / 6
        intNumber /= 6
        System.Console.WriteLine("Division test... " & intNumber)
    End Sub
End Class


Integer calculation

Imports System
public class MainClass
    Shared Sub Main()
       Dim i1 As Integer = 5
       Dim i2 As Integer = 10
       Dim i3 As Integer = 15
       Dim i4 As Integer = 20

       Console.WriteLine(i1 + i2)
       Console.WriteLine(i2 - i3)
       Console.WriteLine(i4/ i1)
       Console.WriteLine(i4 * i2)
    End Sub
End Class


Integer Initialize and assignment

Imports System
public class MainClass
   Shared Public Sub Main(ByVal CmdArgs() As String)
         Dim myInteger As Integer = 7
         Console.WriteLine("Initialized, myInteger: {0}", myInteger)
         myInteger = 5
         Console.WriteLine("After assignment, myInteger: {0}", myInteger)
    End Sub
End Class


Integer Value Demo

Imports System
Public Class MainClass
    
    Shared Sub Main(ByVal args As String())
        Dim n As Integer
        n = 16
        n += 10.23
        Console.WriteLine("Addition test..." & n, "Integer Math")
        n = 24
        n -= 2
        Console.WriteLine("Subtraction test..." & n, "Integer Math")
        n = 6
        n *= 10
        Console.WriteLine("Multiplication test..." & n, "Integer Math")
        n = 12
        n /= 6
        Console.WriteLine("Division test..." & n, "Integer Math")
    End Sub
End Class