VB.Net - 其他操作符

2018-12-16 13:45 更新

有很少其他重要的操作系统支持VB.Net。

运算符描述示例
AddressOfReturns the address of a procedure.
返回过程的地址。
AddHandler Button1.Click,
AddressOf Button1_Click
AwaitIt is applied to an operand in an asynchronous method or lambda expression to suspend execution of the method until the awaited task completes.
它应用于异步方法或lambda表达式中的操作数,以挂起该方法的执行,直到等待的任务完成。
 
Dim result As res
= Await AsyncMethodThatReturnsResult()
Await AsyncMethod()
GetTypeIt returns a Type object for the specified type. The Type object provides information about the type such as its properties, methods, and events.
它返回指定类型的Type对象。 Type对象提供有关类型的信息,例如其属性,方法和事件。
MsgBox(GetType(Integer).ToString())
Function ExpressionIt declares the parameters and code that define a function lambda expression.
它声明定义函数lambda表达式的参数和代码。
Dim add5 = Function(num As
 Integer) num + 5
'prints 10
Console.WriteLine(add5(5))
IfIt uses short-circuit evaluation to conditionally return one of two values. The If operator can be called with three arguments or with two arguments.
它使用短路评估有条件地返回两个值之一。 可以使用三个参数或两个参数调用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

以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号