带空括号的Lambda表达式() [英] Lambda expression with empty paren ()

查看:136
本文介绍了带空括号的Lambda表达式()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了类似这样的代码:

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();

在其lambda表达式中使用()

.那是什么意思 ?它只是用作占位符吗?

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

推荐答案

这仅表示它是一个空参数列表-适用于没有任何参数的委托类型.

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

您可以写x => x.Id的事实实际上只是(x) => x.Id的简写,而这反过来又是(Vehicle x) => x.Id的简写.这只是一个参数列表.

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.

这篇关于带空括号的Lambda表达式()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆