How to filter Application.OpenForms collection with Linq?

I would like to use Where

to filter a collection Application.OpenForms

with Linq and a few questions on this site [1] [2] [3] show that all I need to do this is access a property AllKeys

. 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?

+3


source to share


1 answer


You should use it with FormCollection

no implements IEnumerable<T>

, but only IEnumerable

:

var query = Application.OpenForms.Cast<Form>()
    .Where(form => ...);

      



However, Form

it has no property AllKeys

. Are you confusing web forms and winforms? The first is not Application.OpenForms

.

+4


source







All Articles