icl*_*126 5 c# listview casting
有没有办法投listView.SelectedIndices来List<int>?
我试过这个
(List<int>)reListViewAllMovies.SelectedIndices.Cast<List<int>>()
Run Code Online (Sandbox Code Playgroud)
但它不起作用(InvalidCastException).
如果解决方案不存在,是否有任何"单行"解决方案,例如使用lambda表达式?
老问题,但我一直在寻找解决方案..NET v4.5.我不知道该框架的早期版本.
var list = myListView.SelectedIndices.Cast<int>().ToList();
Run Code Online (Sandbox Code Playgroud)
reListViewAllMovies.SelectedIndices.Select(i => (int)i).ToList();
Run Code Online (Sandbox Code Playgroud)
或者,您可以使用foreach循环来转换结果:
var newList = new List<int>();
foreach(int i in reListViewAllMovies.SelectedIndices)
{
newList.Add(i);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1415 次 |
| 最近记录: |