I would like to use Where to filter the Application.OpenForms collection with Linq, and several questions on this site  [1] [2] [3] suggest that all I that need in order to do that is access its AllKeys property. However, even when I create a new Windows Forms application, the collection doesn't seem to have this property at all and doesn't compile when I try to use it. What could be the reason?
You have to cast it since FormCollection doesn't implement  IEnumerable<T> but only IEnumerable:
var query = Application.OpenForms.Cast<Form>()
    .Where(form => ...);
However, the Form has no AllKeys property. Are you confusing webforms and winforms?  In the former there is no Application.OpenForms.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With