c# - Generic Method Fails to Utilize Covariance on IEnumerable<T> -
i wondering why following code fails compile, exception "instance argument: cannot convert 'system.collections.generic.ienumerable<timpl>' 'system.collections.generic.ienumerable<tinterface>'":
public static list<tinterface> foo<tinterface, timpl>(ienumerable<timpl> input) timpl : tinterface { return input.tolist<tinterface>(); } i know change return line input.cast<tinterface>().tolist() instead, want understand why code written doesn't compile. in mind, seems though compiler should able verify input can implicitly cast ienumerable<tinterface>.
Comments
Post a Comment