我有以下继承:这个通用演员为什么会失败?
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.List 1[xRow]' to type 'System.Collections.Generic.IEnumerable
1 TeraRow]
而且为什么我要投它呢?
这种类型的演员将在C#4.0中得到支持,将在今年晚些时候发布。解决此问题的功能称为协变通用参数。 – 2009-07-15 19:19:23