【发布时间】:2019-06-04 19:30:42
【问题描述】:
我有一堆返回 GridTiles 列表的方法,例如 GetTopNeighbour。我希望能够使用 GetNeighboursHandler 委托作为参数将它们传递给 AutoConnect 方法。
public delegate List<GridTile> GetNeighboursHandler(GridTile c);
public List<GridTile> GetTopNeighbour(GridTile c)
{
//do stuff and return list
return null;
}
public GridTile AutoConnect(GridTile c, GetNeighboursHandler del)
{
List<GridTile> tempList = del(c);
// do stuff with the tempList
}
public void Test(GridTile c)
{
AutoConnect(c, GetTopNeighbour(c));
}
在测试方法中,我收到错误:... 无法将 ...Generic.List... 转换为 GetNeighboursHandler。 我是否完全误解了代表的工作方式?
【问题讨论】: