Reputation: 44285
BindingSource source = new BindingSource();
source.Add(new List<string>() { "1", "2", "3" });
//List<string> theList = source.List;//compile fail. Can't convert from IList to List<T> implicity
List<string> theList = source.List as List<string>;//fail, null
I've seen people online creating a method to perform an explicit conversion. This seems like total overkill for this task. Is there a better way to get my list back?
Upvotes: 2
Views: 3477
Reputation: 887657
You're adding a List<T>
as the first item in the list.
To retrieve it, you would write
(List<string>) source.List[0];
Your code would work if you actually bind to a List<T>
by setting the DataSource
property.
Upvotes: 9