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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.