【发布时间】:2015-08-29 20:33:58
【问题描述】:
我有一个关于我以前在 C# 中从未见过的东西的问题。在新的asp.net依赖注入中的服务提供者中,有一个带有return _ => null;的方法
有问题的方法:
private Func<MyServiceProvider, object> CreateServiceAccessor(Type serviceType)
{
var callSite = GetServiceCallSite(serviceType, new HashSet<Type>());
if (callSite != null)
{
return RealizeService(_table, serviceType, callSite);
}
return _ => null;
}
_ 是什么?它是 C# 6 中的新功能吗?搜索return _ 不会返回任何有用的信息,除非您需要命名约定。
【问题讨论】:
-
这是你的 Func 参数的名称
-
与
return delegate (int _) { return null; };相同,其中_是未使用的参数(因此无需提供正确名称)。