Michal Fiala Michal Fiala - 26 days ago 9
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)