2

我有以下代码:

public void Test(Request request, Func<IEnumerable<Building>> buildings)
{
   vm.Buildings = Helper.GenerateDropdownList(request.BuildingId,() => buildings());
}

我现在想向buildings()回调传递一个额外的参数

public void Test(Request request, Func<IEnumerable<Building>> buildings)
{
   var cityId = GetCity();
   vm.Buildings = Helper.GenerateDropdownList(request.BuildingId,() => buildings(cityId));
}

输入该参数的正确方法是什么?

4

1 回答 1

3

您的buildings代表将需要是 aFunc<T, TResult>而不是 a Func<TResult>

假设cityIdint

public void Test(Request request, Func<int, IEnumerable<Building>> buildings)
{
   var cityId = GetCity();
   m.Buildings = Helper.GenerateDropdownList(request.BuildingId,
                                             () => buildings(cityId));
}
于 2013-07-20T04:22:20.127 回答