ViewsCollection - IEnumerable<object>

Apr 22, 2009 at 3:29 PM
In ViewsCollection implementation, I see it implements IEnumerable<object>.
Is there a reason why IEnumerable isn't used instead?  Perhaps there are some advantages to using the generic version that I'm not aware of?

Apr 22, 2009 at 8:13 PM

Hi Jiho,


As IEnumerable<T> implements IEnumerable, when a class implements the generic interface IEnumerable<object> it is already implementing IEnumerable also.

One advantage I can think of is enabling Linq. Most Linq method are not accessible for classes that implement the non-generic IEnumerable.


Also, I personally think that IEnumerabe<object> is more meaningful that just IEnumerable. When I read a method that returns IEnumerable<object> I'm sure that it will contain any kind of object. Instead a method that returns a IEnumerable does not say much about what kind of objects it will contain.   


Hope it helps!


Matias Bonaventura

Apr 23, 2009 at 1:12 AM
I don't really buy the argument regarding IEnumerable<object> conveying more meaning than IEnumerable - I think it's rather ugly.  I've had to use Action<object> and Predicate<object> but I'd use Action or Predicate if they were available in a heartbeat.
But Linq support is something I didn't think of.  Linq support is definitely a plus.