- VB.Net 基礎教程
- VB.Net - 首頁
- VB.Net - 概述
- VB.Net - 環境搭建
- VB.Net - 程式結構
- VB.Net - 基本語法
- VB.Net - 資料型別
- VB.Net - 變數
- VB.Net - 常量
- VB.Net - 修飾符
- VB.Net - 語句
- VB.Net - 指令
- VB.Net - 運算子
- VB.Net - 決策制定
- VB.Net - 迴圈
- VB.Net - 字串
- VB.Net - 日期和時間
- VB.Net - 陣列
- VB.Net - 集合
- VB.Net - 函式
- VB.Net - 子程式
- VB.Net - 類和物件
- VB.Net - 異常處理
- VB.Net - 檔案處理
- VB.Net - 基本控制元件
- VB.Net - 對話方塊
- VB.Net - 高階窗體
- VB.Net - 事件處理
- VB.Net 高階教程
- VB.Net - 正則表示式
- VB.Net - 資料庫訪問
- VB.Net - Excel表格
- VB.Net - 傳送郵件
- VB.Net - XML處理
- VB.Net - Web程式設計
- VB.Net 有用資源
- VB.Net - 快速指南
- VB.Net - 有用資源
- VB.Net - 討論
VB.Net - 其他運算子
VB.Net 還支援其他一些重要的運算子。
| 運算子 | 描述 | 示例 |
|---|---|---|
| AddressOf | 返回過程的地址。 |
AddHandler Button1.Click, AddressOf Button1_Click |
| Await | 它應用於非同步方法或lambda表示式中的運算元,以掛起方法的執行,直到等待的任務完成。 |
Dim result As res = Await AsyncMethodThatReturnsResult() Await AsyncMethod() |
| GetType | 它為指定的型別返回一個 Type 物件。Type 物件提供有關該型別的資訊,例如其屬性、方法和事件。 |
MsgBox(GetType(Integer).ToString()) |
| 函式表示式 | 它宣告定義函式lambda表示式的引數和程式碼。 |
Dim add5 = Function(num As Integer) num + 5 'prints 10 Console.WriteLine(add5(5)) |
| If | 它使用短路求值來有條件地返回兩個值之一。If 運算子可以用三個引數或兩個引數呼叫。 |
Dim num = 5 Console.WriteLine(If(num >= 0, "Positive", "Negative")) |
示例
以下示例演示了其中一些運算子:
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
編譯並執行上述程式碼後,將產生以下結果:
System.Int32 System.Double System.String 25 Positive
vb.net_operators.htm
廣告