Possible duplicate:No type inference with universal extension method
Consider two methods:
public static IEnumerable<V> Merge<V> (this IEnumerable<IEnumerable<V>> coll) public static IEnumerable<V> Merge<T, V> (this IEnumerable<T> coll) where T : IEnumerable<V>
Both compile just fine, in both cases the type of the generic types will be known at the time the caller compiles, and therefore the exact type of the extended type.
You can name both the penalty, and only the first as an extension.
Why?
To see that this fails, use the second method and an example like this:
var x = new List<List<int>>(); var y = x.Merge();
Don't you guys think the original WAY message is too complicated to get a clear picture? For educational purposes, I think this post should not be closed, even if technically (i.e. the Answer) it is duplicated. Only my 2 cents.
.
. . .
, , CAN NOT , IntelliSense , V .
V
, ,
// IEnumerable<IEnumerable<int>> definition... List<List<int>> x = ...; // calls your first method (implicitly) x.Merge(); // also calls your first method (explicitly) x.Merge<int>(); // calls your second method (explicitly) x.Merge<List<int>, int>();
, , , , intellisense, ...
. , , , /. , Merge() , T V , , , S.O. .