如何将IList转换回BindingSource中的List <T>?

P.B*_*key 2 c#

    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
Run Code Online (Sandbox Code Playgroud)

我在网上看到人们创建了一种执行显式转换的方法.对于这项任务来说,这似乎完全有点过头了.有没有更好的方法让我的名单回来?

SLa*_*aks 9

您将添加a List<T>作为列表中的第一项.

要检索它,你会写

(List<string>) source.List[0];
Run Code Online (Sandbox Code Playgroud)

如果List<T>通过设置DataSource属性实际绑定到a ,则代码将起作用.