Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 C# 或 VB 中,如何将 listview 项目集合添加到列表但不使用循环对其进行迭代?
原因是我想改进这一点:
For Each Item As ListViewItem In ListView.Items List.Add(Item) Next
对于这样的事情:
List.AddRange(DirectCast(ListView.Items, ...))
您可以使用 LINQ:
list.AddRange(listView.Items.Cast<ListViewItem>().Select(lvi => lvi.Text));
您可以使用Cast<T>:
Cast<T>
List.AddRange(ListView.Items.Cast<WhatTypeAmI>());