Michal Fiala Michal Fiala - 5 months ago 33
Vb.net Question

Lambda expression in Visual Basic

I program in C# and I need to do lambda expression in Visual Basic same as:

var password = Database.Users.Where(x => x.username == username).FirstOrDefault();

Answer Source

x => is replaced with Function(x) in VB.NET

The full line becomes

Dim password = Database.Users.Where(Function(x) x.username = username).FirstOrDefault()

But can also be written like:

Dim password = Database.Users.FirstOrDefault(Function(x) x.username = username)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download