I asked a question earlier with regards to using generic vs base class in a method taking in a List<T>
. It was quickly pointed out that you can't pass a List<Derived>
into a method expecting a List<Base>
.
Further exploration (along with helpful links such as this one) show that while you can't pass List<Derived>
to List<Base>
, you can pass List<Derived>
to IEnumerable<Base>
(due to contravariance/covariance in .NET 4).
So like in my previous question, I present the same one here: Since there doesn't appear to be a difference in using these two options, which would be better? Is it strictly a style-based thing, or are there implications to using one over the other?
Option A: void DoWork<TBase>(IEnumerable<TBase> objs) where TBase : Base;
Option B: void DoWork(IEnumerable<Base> objs);