Berikut adalah Operator Visual Basic /Net :
1. Aritmatika
Aritmatika digunakan untuk melakukan operasi matematika seperti penambahan, pengurangan, pembagian, perkalian, dll.,
| Operator | Keterangan |
| + | Penambahan |
| - | Pengurangan |
| * | Perkalian |
| / | Pembagian |
| ^ | Pangkat |
| \ | Hasil Bagi |
| Mod | Sisa Bagi |
Contoh :
Module operatorsSub Main()Dim x As Integer = 15Dim y As Integer = 3Console.WriteLine("x + y: {0}", x+y)Console.WriteLine("x - y: {0}", x-y)Console.WriteLine("x * y: {0}", x*y)Console.WriteLine("x / y: {0}", x/y)Console.WriteLine("x \ y: {0}", x\y)Console.WriteLine("x MOD y: {0}", x Mod y)Console.WriteLine("x ^ y: {0}", x^y)End SubEnd Module
Output :
x + y = 18x - y = 12x * y = 45x \ y = 5x / y = 5x MOD y = 0x ^ y = 3375
2. Perbandingan
Operator perbandingan digunakan untuk membandingkan nilai yang berbeda. Operator ini biasanya mengembalikan nilai Boolean True or False tergantung kondisi.
| Operator | Keterangan |
| = | Sama Dengan |
| <> | Tidak Sama Dengan |
| > | Lebih Besar |
| < | Lebih Kecil |
| >= | Lebih Besar Sama Dengan |
| <= | Lebih Kecil Sama Dengan |
| Is | Perbandingan 2 object yang sama maka true |
| IsNot | Perbandingan 2 object yang tidak sama maka false |
| Like | Perbandingan String yang ada dipada data |
Contoh :
Module operatorsSub Main()
Dim x As Integer = 10Dim y As Integer = 12Console.WriteLine("x > y is:{0}", x > y)Console.WriteLine("x < y is:{0}", x < y)Console.WriteLine("x = y is:{0}", x = y)Console.WriteLine("x <> y is:{0}", x <> y)Console.WriteLine("x >= y is:{0}", x >= y)Console.WriteLine("x <= y is:{0}", x <= y)
End SubEnd Module
Output :
x > y is Falsex < y is Truex = y is Falsex <> y is Truex >= y is Falsex <= y is True
3. Logika/Bitwise
| Operator | Keterangan |
| And | 2 Kondisi benar = true, jika tidak = false |
| Or | Salah satu benar = true |
| Not | Jika benar maka nilai = false |
| Xor | Jika kedua kondisi sama = true |
| AndAlso | Ini hanya berkerja pada tipe boolean |
| OrElse | Ini hanya berkerja pada tipe boolean |
| IsFalse | Menentukan apakah kondisi salah |
| IsTrue | Menentukan apakah kondisi benar |
contoh :
Module operatorsSub Main()
Dim x As Boolean = TrueDim y As Boolean = FalseConsole.WriteLine("x And yis:{0}", x And y)Console.WriteLine("x or y is:{0}", x Or y)Console.WriteLine("not y is:{0}", Not y)
End SubEnd Module
Output :
x and y is Falsex or y is Truenot x is False
4. Bit Shift Operators
Bit Shift digunakan untuk melakukan operasi shift pada level / nilai biner. x dan y adalah Nilai numerik.
| Operator | Keterangan |
| And | Bitwise menyalin sedikit ke hasil jika ada kedua operator |
| Or | Bitwise menyalin sedikit ke hasil jika ada salah satu operator |
| Xor | Menset Bit jika salah satu diatur |
| Not | Mengaktifkan Bit |
| << | Mengeser ke kiri |
| >> | Mengeser ke kanan |
5. Assignment Operators
| Operator | Contoh |
| = | x = 3 |
| += | x += 3 |
| -= | x -= 3 |
| *= | x *= 3 |
| /= | x /= 3 |
| \= | x \= 3 |
| ^= | x ^= 3 |
| <<= | x <<= 3 |
| >>= | x >>= 3 |
| &= | x &= 3 |
6. Miscellaneous Operators
| Operator | Contoh |
| AddressOf | AddHandler Button1.Click, AddressOf Button1_Click |
| Await | Dim result As res = Await AsyncMethodThatReturnsResult() Await AsyncMethod() |
| GetType | MsgBox(GetType(Integer).ToString()) |
| Function Expression | Dim add5 = Function(num As Integer) num + 5 ‘prints 10 Console.WriteLine(add5(5)) |
| If | Dim num = 5 Console.WriteLine(If(num >= 0, “Positive”, “Negative”)) |