I’ve been using LINQ for awhile (and enjoy it), but it feels like I hit a speedbump when I run across .NET specialized collections(DataRowCollection, ControlCollection). Is there a way to use LINQ with these specialized controls, and if not do you think Microsoft will address this in the next release of the framework? Or are we left to iterate over these the non-LINQ way, or pull the items out of the collection into LINQ-able collections ourselves?
Share
The reason why collections like
ControlCollectiondo not work with LINQ is that they are not strongly typed. Without an element type LINQ cannot create strongly typed methods. As long as you know the type you can use theCastmethod to create a strongly typed enumeration and hence be used with LINQ. For exampleAs to will Microsoft ever make these implement
IEnumerable<T>by default. My guess is no here. The reason why is that doing so is a breaking change and can cause expected behavior in code. Even simply implementingIEnumerable<Control>forControlCollectionwould cause changes to overload resolution that can, and almost certainly will, break user applications.