Vb.net-misc-operators

提供:Dev Guides
移動先:案内検索

VB.Net-その他のオペレーター

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"))

次の例は、これらの演算子の一部を示しています-

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