Vb.net lambda syntax features

Source: Internet
Author: User

Vb.net lambda syntax features:

The lambda expression has no name.

Lambda expressions cannot have modifiers, such as Overloads or Overrides.

Lambda expressions do not use the As clause to specify the function return type. On the contrary, the type is derived from the value calculated by the lambda expression body. For example, if the body of a lambda expression is Where cust. City = "London", the return type is Boolean.

The function must be an expression rather than a statement. The function body can contain calls to the function process, but cannot contain calls to the child process.

The Return statement does not exist. The value returned by the function is the value of the expression in the function body.

The End Function statement does not exist.

Either all parameters must have the specified data type or all types must be inferred.

Optional and Paramarray parameters are not allowed.

Generic parameters are not allowed.

Due to the above restrictions, and the use of lambda expressions, lambda expressions are generally short and not complex.

 

Example:

Private Sub Button3_Click (ByVal sender As System. Object, ByVal e As System. EventArgs) Handles Button3.Click
Dim ArrInt As New List (Of Integer)
For I As Integer = 1 To 20
ArrInt. Add (I)
Next

Dim EvenOne As New List (Of Integer)
EvenOne = ArrInt. FindAll (New Predicate (Of Integer) (AddressOf EvenGetter ))
For Each m In EvenOne
Console. WriteLine (m)
Next

Dim EvenTwo As New List (Of Integer)
EvenTwo = ArrInt. FindAll (Function (p As Integer) p Mod 2 = 0)
For Each m In EvenTwo
Console. WriteLine (m)
Next

End Sub

Public Function EvenGetter (ByVal p As Integer) As Boolean
Return p Mod 2 = 0
End Function

Author: "wl58796351 column"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.