- VB.Net Basic Tutorial
- VB.Net - Home
- VB.Net - Overview
- VB.Net - Environment Setup
- VB.Net - Program Structure
- VB.Net - Basic Syntax
- VB.Net - Data Types
- VB.Net - Variables
- VB.Net - Constants
- VB.Net - Modifiers
- VB.Net - Statements
- VB.Net - Directives
- VB.Net - Operators
- VB.Net - Decision Making
- VB.Net - Loops
- VB.Net - Strings
- VB.Net - Date & Time
- VB.Net - Arrays
- VB.Net - Collections
- VB.Net - Functions
- VB.Net - Subs
- VB.Net - Classes & Objects
- VB.Net - Exception Handling
- VB.Net - File Handling
- VB.Net - Basic Controls
- VB.Net - Dialog Boxes
- VB.Net - Advanced Forms
- VB.Net - Event Handling
- VB.Net Advanced Tutorial
- VB.Net - Regular Expressions
- VB.Net - Database Access
- VB.Net - Excel Sheet
- VB.Net - Send Email
- VB.Net - XML Processing
- VB.Net - Web Programming
- VB.Net Useful Resources
- VB.Net - Quick Guide
- VB.Net - Useful Resources
- VB.Net - Discussion
VB.Net - Miscellaneous Operators
There are few other important operators supported by VB.Net.
Operator | Description | Example |
---|---|---|
AddressOf | Returns the address of a procedure. |
AddHandler Button1.Click, AddressOf Button1_Click |
Await | It is applied to an operand in an asynchronous method or lambda expression to suspend execution of the method until the awaited task completes. |
Dim result As res = Await AsyncMethodThatReturnsResult() Await AsyncMethod() |
GetType | It returns a Type object for the specified type. The Type object provides information about the type such as its properties, methods, and events. |
MsgBox(GetType(Integer).ToString()) |
Function Expression | It declares the parameters and code that define a function lambda expression. |
Dim add5 = Function(num As Integer) num + 5 'prints 10 Console.WriteLine(add5(5)) |
If | It uses short-circuit evaluation to conditionally return one of two values. The If operator can be called with three arguments or with two arguments. |
Dim num = 5 Console.WriteLine(If(num >= 0, "Positive", "Negative")) |
Example
The following example demonstrates some of these operators −
Module assignment Sub Main() Dim a As Integer = 21 Console.WriteLine(GetType(Integer).ToString()) Console.WriteLine(GetType(Double).ToString()) Console.WriteLine(GetType(String).ToString()) Dim multiplywith5 = Function(num As Integer) num * 5 Console.WriteLine(multiplywith5(5)) Console.WriteLine(If(a >= 0, "Positive", "Negative")) Console.ReadLine() End Sub End Module
When the above code is compiled and executed, it produces the following result −
System.Int32 System.Double System.String 25 Positive
vb.net_operators.htm
Advertisements
To Continue Learning Please Login
Login with Google