VB.Net/Language Basics/Operator Logic — различия между версиями

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

Версия 16:40, 26 мая 2010

And, Or, Xor and Not Operator

Imports System
public class MainClass
    Shared Sub Main()
       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

Imports System
Public Class MainClass
    Shared Sub Main(ByVal args As String())
       Dim valueOne As Integer = 10
       Dim valueTwo As Integer = 20
       Dim valueThree As Integer = 30
       If valueOne > valueTwo Then
          Console.WriteLine("ValueOne: {0} larger than ValueTwo: {1}", valueOne, valueTwo)
       End If
       If valueThree > valueTwo Then
          Console.WriteLine("ValueThree: {0} larger than ValueTwo: {1}",valueThree, valueTwo)
       End If
       
       If valueTwo > 15 Then 
          Console.WriteLine("Yes it is")
       End If   
    End Sub

End Class


Relation operator: less, bigger

Imports System
Public Class MainClass
    Shared Sub Main()
        Dim intNumber As Integer
        intNumber = 20
        "Is intNumber less than or equal to 27?
        If intNumber <= 27 Then
            System.Console.WriteLine("Is "intNumber" less than or equal to 27? Yes!")
        Else
            System.Console.WriteLine("Is "intNumber" less than or equal to 27? No!")
        End If
        "Is intNumber greater than 27?
        If intNumber > 27 Then
            System.Console.WriteLine("Is "intNumber" greater than 27? Yes!")
        Else
            System.Console.WriteLine("Is "intNumber" greater than 27? No!")
        End If
        "Is intNumber greater than or equal to 27?
        If intNumber >= 27 Then
            System.Console.WriteLine("Is "intNumber" greater than or equal to 27? Yes!")
        Else
            System.Console.WriteLine("Is "intNumber" greater than or equal to 27? No!")
        End If
    End Sub
End Class