Dhinesh
Dhinesh

Reputation: 45

DataRow need to be casted before linq operations . Why?

DataRowCollection : InternalDataCollectionBase

InternalDataCollectionBase : ICollection, IEnumerable

So , DataRowCollection indirectly inherites IEnumerable. Generally , If a class inherites IEnumerable we can apply linq operations . But in DataRowCollection this fails . Why?

Upvotes: 0

Views: 132

Answers (1)

Matthew King
Matthew King

Reputation: 5194

Most of the Linq extension methods (from System.Linq.Enumerable) operate on a generic System.Collections.Generic.IEnumerable<T>, rather than the non-generic System.Collections.IEnumerable that InternalDataCollectionBase implements. That's why you use the Cast (or OfType) extension method to turn your IEnumerable into an IEnumerable<DataRow>.

Upvotes: 2

Related Questions