【发布时间】:2015-06-11 01:27:32
【问题描述】:
我有一个 StringCollection 对象正在通过 ReportParameter 对象传递,我需要将其改为 List<int>。
到目前为止,我已经尝试过了
List<int> ids = (parameters != null) ? parameters[parameters.FindIndex(x => x.Name == "IDs")].Values.Cast<int>().ToList() : null;
它应该检查参数对象是否为空,如果不是,它会找到 IDs 参数的索引,然后尝试将值转换为整数列表。我不断收到Cast is not valid 错误。我将如何将 StringCollection 转换为 List<int> ?
【问题讨论】:
-
“Cast is not valid”是无效错误。请发布完整的编译器错误以及 CSXXXX 错误代码。
-
List<string>->List<int>包含在链接副本中,StringCollection->List<string>包含在 stackoverflow.com/questions/844412/… 中(根据需要组合/重构)