The reason is that a List<IJob>
is not a List<Job>
, although a Job
implements IJob
.
This is co- or contra-variance (I never remember which is which.)
The thinking goes something like this:
The compiler cannot guarantee that AddRange
only reads things out of the parameter it is given, and thus it cannot guarantee that this is safe, and thus it fails to compile.
For instance, for all the compiler knows, AddRange could add another object into the jobs
parameter, that implements IJob
(because AddRange expects IJob
collections), but isn't Job
, which is what jobs
expect, and thus that would not be safe.
In C# 4.0, there is some support for handling this, but I'm not sure it would handle your particular case since the support has to be specified on the interface-level, and not at the method-level.
In other words, you would have to specify on the interface type that everything that relates to T is only going into the collection, never out of it, and then the compiler would allow you do this. However, a collection you cannot read from would be pretty pointless.