【发布时间】:2009-07-15 19:12:42
【问题描述】:
我有以下继承:
internal abstract class TeraRow{}
internal class xRow : TeraRow {} // xRow is a child of TeraRow
public IEnumerable<TeraRow> Compare(MappedTables which, DateTime selectionStart
, DateTime selectionEnd, string pwd)
{
IEnumerable<xRow> result=CompareX();
return (IEnumerable<TeraRow>)result; //Invalid Cast Exception?
}
无法转换类型为“System.Collections.Generic.List1[xRow]' to type 'System.Collections.Generic.IEnumerable1[TeraRow]”的对象
为什么我还需要投射它?
【问题讨论】:
-
今年晚些时候发布的 C# 4.0 将支持这种类型的转换。解决此问题的功能称为协变泛型参数。
标签: .net generics casting ienumerable