Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Examples of VB.NET lambda expression

Tags:

vb.net

linq

Where can I find complex LINQ examples made using VB.NET Lambda Expression syntax?

During my searches I always found 101 LINQ Samples but they use the other notation and for me is not always clear how to transform that code into a lambda expression.

like image 272
Drake Avatar asked Feb 03 '11 08:02

Drake


People also ask

What is a lambda expression example?

Lambda expressions basically express instances of functional interfaces (An interface with single abstract method is called functional interface. An example is java.lang.Runnable).

What is lambda expression in VB net?

A lambda expression is a function or subroutine without a name that can be used wherever a delegate is valid. Lambda expressions can be functions or subroutines and can be single-line or multi-line. You can pass values from the current scope to a lambda expression.

What is lambda expression in .NET framework?

Lambda expressions in C# are used like anonymous functions, with the difference that in Lambda expressions you don't need to specify the type of the value that you input thus making it more flexible to use. The '=>' is the lambda operator which is used in all lambda expressions.

How many types of lambda expressions are there?

Types of Lambda Body In Java, the lambda body is of two types. () -> System. out. println("Lambdas are great");


1 Answers

You could just look at MSDN. They have at least one example for each of the IEnumerable-extensions in C# and also in VB.Net.

Some random examples:

' Select
Dim squares As IEnumerable(Of Integer) = _
        Enumerable.Range(1, 10).Select(Function(x) x * x)

' Aggregate
Dim reversed As String = _
        words.Aggregate(Function(ByVal current, ByVal word) word & " " & current)

' Max
Dim max As Integer = pets.Max(Function(pet) _
                                      pet.Age + pet.Name.Length)

 ' SkipWhile
Dim query As IEnumerable(Of Integer) = _
        amounts.SkipWhile(Function(amount, index) _
                              amount > index * 1000)
like image 65
sloth Avatar answered Oct 02 '22 06:10

sloth