User login |
LinQ and Forms
Iterating a Form's controls:
var qry = from c in this.Controls.OfType<Control>()
select c;
foreach ( var c in qry )
MessageBox.Show( c.Name + ":" + c.GetType().ToString(), "Control Type" );
The Controls collection is not directly usable in the query - the OfType method performs the necessary conversions.
To grab all controls of a specific type:
var q2 = from c in this.Controls.OfType<NumericUpDown>() select c;
|