Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write a VB.Net Lambda expression

I am working on a VB.net project now. I am new to VB.Net LINQ and would like to know the Lambda equivalent of

var _new = orders.Select(x => x.items > 0); 

in VB.Net.

Someone please suggest!

like image 604
Venugopal M Avatar asked Aug 19 '13 15:08

Venugopal M


People also ask

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 does => mean in lambda?

In lambda expressions, the lambda operator => separates the input parameters on the left side from the lambda body on the right side.

What is lambda expression explain with example?

A lambda expression is a short block of code which takes in parameters and returns a value. Lambda expressions are similar to methods, but they do not need a name and they can be implemented right in the body of a method.


1 Answers

The lambda syntax isn't that much different than creating a regular delegate.

If creating a lambda which has a return value, use Function. Otherwise if you're creating one that doesn't, use Sub.

Dim _new = orders.Select(Function(x) x.Items > 0)  Dim action As Action(Of Item) = Sub(x) Console.WriteLine(x.Items) 
like image 91
Jeff Mercado Avatar answered Sep 23 '22 15:09

Jeff Mercado