How to convert IList back to List<T> in a BindingSource?

c#

Solution

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.

Problem

``` 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?

Original source