我正在尝试使用下面的代码将 ICollection 转换为 List -
ICollection<DataStructure> list_Stuctures = dataConnectorService.ListStructures(dataConnector, SupportedDataStructures.All);
List<DataStructure> lst_DataStructure = new List<DataStructure>();
list_Stuctures.CopyTo(lst_DataStructure);
在最后一行,我得到以下异常 -
异常 = 目标参数计数异常
消息 = 参数计数不匹配。
如何将 ICollection 转换为 List?
最简单的转换方法ICollection
to a List
LINQ 的用法如下(MSDN https://msdn.microsoft.com/en-us/library/bb342261(v=vs.100).aspx)
List<T> L = C.ToList();
不要忘记添加
using System.Linq;
否则ToList()
不可用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)