Convert SelectedObjectCollection to Collection of Specific Type
- by Jonathan Wood
I have a WinForms multiselect listbox, and each item in the listbox is of type MyClass.
I am also writing a method that needs to take a parameter that is a collection of MyClass. It could be of type MyClass[], List<MyClass>, IList<MyClass>, IEnumerable<MyClass>, etc. Any of those would work fine.
Somehow, I need to pass the selected items in the listbox to my method. But how would I convert SelectedObjectCollection to any of the MyClass collection types described above?