I want to list all controls inside another control which have names starting with “btnOverlay”. I can’t use Controls.Find, because it needs an exact match. I believe I can use LINQ for this, but I’m not very experienced on that. Is it possible? How can I do it?
I’m using .NET 4.0.
You could search for them with LINQ via:
The
Cast<T>call is required, asControlCollectiondoes not implementIEnumerable<T>, onlyIEnumerable. Also, this doesn’t do a recursive search, but only searches the contained controls directly. If recursion is required, you’ll likely need to refactor this into a method similar to this answer.