I am using C# and targeting the .NET Framework 3.5. I\'m looking for a small, succinct and efficient piece of code to copy all of the items in a ListBox to a List
List
The following will do it (using Linq):
List list = lbMyListBox.Items.OfType().ToList();
The OfType call will ensure that only items in the listbox's items that are strings are used.
Using Cast, if any of the the items are not strings, you will get an exception.