Compact operators : Operator « Operator « VB.Net Tutorial






Public Class Tester


    Public Shared Sub Main
        Dim result As New System.Text.StringBuilder

        Dim testDouble As Double = Math.PI
        result.Append("Double ").AppendLine(testDouble)
        testDouble += Math.PI
        result.Append("+= ").AppendLine(testDouble)
        testDouble *= Math.PI
        result.Append("*= ").AppendLine(testDouble)
        testDouble -= Math.PI
        result.Append("-= ").AppendLine(testDouble)
        testDouble /= Math.PI
        result.Append("/= ").AppendLine(testDouble)
        testDouble ^= Math.PI
        result.Append("^= ").AppendLine(testDouble)
        result.AppendLine()

        Dim testInteger As Integer = 17
        result.Append("Integer ").AppendLine(testInteger)
        testInteger \= 2
        result.Append("\= 2 ... ").AppendLine(testInteger)
        testInteger += 1
        result.Append("+= 1 ... ").AppendLine(testInteger)
        testInteger <<= 1
        result.Append("<<= 1 ... ").AppendLine(testInteger)
        testInteger >>= 3
        result.Append(">>= 3 ... ").AppendLine(testInteger)
        result.AppendLine()

        Dim testString As String = "Abcdef"
        result.Append("String ").AppendLine(testString)
        testString &= "ghi"
        result.Append("&= ghi ... ").AppendLine(testString)
        testString += "jkl"
        result.Append("+= jkl ... ").AppendLine(testString)

        Console.WriteLine(result.ToString())

    End Sub
End Class
Double 3.14159265358979
+= 6.28318530717959
*= 19.7392088021787
-= 16.5976161485889
/= 5.28318530717959
^= 186.656996003562

Integer 17
\= 2 ... 8
+= 1 ... 9
<<= 1 ... 18
>>= 3 ... 2

String Abcdef
&= ghi ... Abcdefghi
+= jkl ... Abcdefghijkl








3.1.Operator
3.1.1.Compact operators
3.1.2.Using an assignment operator to calculate a power of 2
3.1.3.Calculate PI
3.1.4.Prime numbers using the Sieve of Eratosthenes