在我看来有这个代码:
List<Qux>
获得此例外:
int index = Array.FindIndex(ViewBag.EventTypes, (x) => (x.EventCode == Row.EventCode));
我如何在我看来这样做?我需要在viewbag中搜索EventCode的对象数组。还是有另一种方法可以做到这一点吗?
数组的定义和设置如下:
error CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
这是EventTypes对象定义:
// mycorses is a list of events.
EventTypes[] etypes = GetEventTypes(mycourses);
ViewBag.EventTypes = etypes;
答案 0 :(得分:1)
我认为您只需添加as EventTypes[]
就可以了:
int index = Array.FindIndex(ViewBag.EventTypes as EventTypes[],
(x) => (x.EventCode == Row.EventCode));