gpt4 book ai didi

c# - 如何在 BindingSource 中将 IList 转换回 List

转载 作者:行者123 更新时间:2023-11-30 19:29:50 26 4
gpt4 key购买 nike

    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

我在网上看到人们创建了一种方法来执行显式转换。对于这项任务来说,这似乎完全矫枉过正。有没有更好的方法来取回我的列表?

最佳答案

您正在添加 List<T>作为列表中的第一项。

要检索它,您可以这样写

(List<string>) source.List[0];

如果您实际绑定(bind)到一个 List<T>,您的代码将起作用通过设置 DataSource属性(property)。

关于c# - 如何在 BindingSource 中将 IList 转换回 List<T>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10949896/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com