我有模拟类与以下:
private readonly List<SomeObject> m_objectsList = new List<SomeObject>();
public Task<IList<Auto>> Todo(SomeParams params)
{
IEnumerable<Auto> matches = m_objectsList.Select(GetMyObject);
return Task.FromResult<IList<Auto>>(matches.ToArray());
}
private Auto GetMyObject(SomeObject s)
{
Auto newAuto = new Auto
{
Id = s.Id,
Name = s.Name,
};
return newAuto;
}
这是正常的。现在我想这样做:
private readonly Dictionary<SomeObject, SomeParams> m_objectsList2 =
new Dictionary<SomeObject, SomeParams>();
public Task<IList<Auto>> Todo2(SomeParams params)
{
IEnumerable<Auto> matches = m_objectsList2.Select(GetMyObject2);
return Task.FromResult<IList<Auto>>(matches.ToArray());
}
private Auto GetMyObject2(SomeObject s, SomeParams p)
{
Auto newAuto = new Auto();
....//some code
return newAuto;
}
但出现编译器错误CS0411。
2条答案
按热度按时间7ivaypg91#
Dictionary<TKey, TValue>
实现了IEnumerable<KeyValuePair<TKey, TValue>>
,但由于类型不匹配,编译器无法执行method group到委托的转换。请从使用方法组切换到使用lambda:或更改方法的签名(或添加重载):
58wvjzkj2#
可以尝试修改您的Todo2