Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lambda expression with empty paren () [duplicate]

Tags:

c#

lambda

linq

I came across code like:

var vpAlias = null;
var prices = session.QueryOver<Vehicle>()
    .Left.JoinAlias<VehiclePrice>(x => x.VehiclePrice, () => vpAlias, x => x.VehiclePriceTypeId == 1)
    .Where(() => vpAlias.Id == null || vpAlias.VehiclePriceTypeId == 1)
    .Select(x => x.Id, () => vpAlias.Price)
    .ToList();

that uses () in its lambda expressions. What does that mean ? Is it used just as a placeholder ?

like image 968
Cemre Mengü Avatar asked May 23 '14 08:05

Cemre Mengü


1 Answers

It just means it's an empty parameter list - for delegate types which don't have any parameters.

The fact that you can write x => x.Id is really just a shorthand for (x) => x.Id which is in turn a shorthand for (Vehicle x) => x.Id. It's just a parameter list.

like image 147
Jon Skeet Avatar answered Oct 07 '22 15:10

Jon Skeet