VB.Net Tutorial/Operator/Arithmetic Operator — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 16:40, 26 мая 2010
Boolean value with And and Or
Option Strict On
Imports System
Module Module1
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 "Main
End Module
x = 3 And y = 7. False x = 3 Or y = 7. True x = 3 Xor y = 7. True Not x = 3. True
Power calculator
Option Strict On
Imports System
Module Module1
Sub Main( )
Dim value As Integer = 5
Dim power As Integer = 4
Console.WriteLine("{0} to the {1}th power is {2}", _
value, power, value ^ power)
End Sub
End Module
5 to the 4th power is 625
Shortcut assignment operators
Module Tester
Sub Main()
Dim A As Integer
A = 0
A += 10
Console.WriteLine("A += 10 yields " & A)
A -= 5
Console.WriteLine("A -=5 yields " & A)
A *= 3
Console.WriteLine("A *= 3 yields " & A)
A /= 5
Console.WriteLine("A /= 5 yields " & A)
A ^= 2
Console.WriteLine("A = 2 yields " & A)
End Sub
End Module
A += 10 yields 10 A -=5 yields 5 A *= 3 yields 15 A /= 5 yields 3 A ^= 2 yields 9