I'm clearing all the controls on a windows form with the following
form.Controls.Cast<dynamic>().ToList().ForEach(c => { switch (c) { case CheckBox t when c is CheckBox: c.Checked = false; break; case System.Windows.Forms.ComboBox t when c is System.Windows.Forms.ComboBox: c.Items.Clear(); break; case CheckEdit t when c is CheckEdit: c.Checked = false; break; default: c.Text = ""; break; } }); I have to use dynamic because if I dont, I wont get the options for Checked and I also wont be able to clear any items in a combobox or list for that matter.
Is there a neater way of achieving this? I'm using c# 7.3 which allows me to use the when keyword, I wasn't able to find how to do this with anything under 7.0, If there is something for under 7.0, what would it be?