Evenimente
17 mar., 21 - 21 mar., 10
Alăturați-vă seriei de întâlniri pentru a construi soluții AI scalabile bazate pe cazuri de utilizare din lumea reală cu colegi dezvoltatori și experți.
Înregistrați-vă acumAcest browser nu mai este acceptat.
Faceți upgrade la Microsoft Edge pentru a profita de cele mai noi funcții, actualizări de securitate și asistență tehnică.
Declares the parameters and code that define a subroutine lambda expression.
Sub ( [ parameterlist ] ) statement
- or -
Sub ( [ parameterlist ] )
[ statements ]
End Sub
Term | Definition |
---|---|
parameterlist |
Optional. A list of local variable names that represent the parameters of the procedure. The parentheses must be present even when the list is empty. For more information, see Parameter List. |
statement |
Required. A single statement. |
statements |
Required. A list of statements. |
A lambda expression is a subroutine that does not have a name and that executes one or more statements. You can use a lambda expression anywhere that you can use a delegate type, except as an argument to RemoveHandler
. For more information about delegates, and the use of lambda expressions with delegates, see Delegate Statement and Relaxed Delegate Conversion.
The syntax of a lambda expression resembles that of a standard subroutine. The differences are as follows:
A lambda expression does not have a name.
A lambda expression cannot have a modifier, such as Overloads
or Overrides
.
The body of a single-line lambda expression must be a statement, not an expression. The body can consist of a call to a sub procedure, but not a call to a function procedure.
In a lambda expression, either all parameters must have specified data types or all parameters must be inferred.
Optional and ParamArray
parameters are not permitted in lambda expressions.
Generic parameters are not permitted in lambda expressions.
Following is an example of a lambda expression that writes a value to the console. The example shows both the single-line and multiline lambda expression syntax for a subroutine. For more examples, see Lambda Expressions.
Dim writeline1 = Sub(x) Console.WriteLine(x)
Dim writeline2 = Sub(x)
Console.WriteLine(x)
End Sub
' Write "Hello".
writeline1("Hello")
' Write "World"
writeline2("World")
Feedback pentru .NET
.NET este un proiect open source. Selectați un link pentru a oferi feedback:
Evenimente
17 mar., 21 - 21 mar., 10
Alăturați-vă seriei de întâlniri pentru a construi soluții AI scalabile bazate pe cazuri de utilizare din lumea reală cu colegi dezvoltatori și experți.
Înregistrați-vă acum