【发布时间】:2011-08-05 11:15:09
【问题描述】:
我试图在多个 ISet 上使用 Concat() 来制作一个更大的 ISet。所以我尝试了以下代码:
public class Foo
{
private Dictionary<Bii, ISet<Faa>> items = new Dictionary<Bii, ISet<Faa>>();
public ISet<Faa> GetCompleteList()
{
ISet<Faa> result = items.Values.Aggregate((x,y) => x.Concat(y));
return result;
}
}
问题是这会导致编译器错误:
无法将类型
System.Collections.Generic.IEnumerable<Faa>隐式转换为System.Collections.Generic.ISet<Faa>。存在显式转换(您是否缺少演员表?)
还有第二个错误:
无法将 lambda 表达式转换为委托类型
System.Func<System.Collections.Generic.ISet<Faa>,System.Collections.Generic.ISet<Faa>,System.Collections.Generic.ISet<Faa>>,因为块中的某些返回类型不能隐式转换为委托返回类型
我也尝试过使用这样的演员:
ISet<Faa> result = items.Values.Aggregate((x,y) => (ISet<Faa>)x.Concat(y));
但这会给我一个InvalidCastException,因为它应该是ConcatIterator 或某种形式。
如何进行良好的演员表以将所有 ISet 加入一个 ISet?
【问题讨论】:
标签: c# set-theory