C# · 12月 31, 2021

Linq从ListViewItemCollections中选择项目在c#

如何在ListViewItemCollections中使用 Linq在C#中选择ListViewItem?

新新200的X- 200 X- 200 200 X- 200 200 X- 200 200 X- 1992 200 X-

ListViewItemCollections lv = listview1.items;var test = from xxx in lv where xxx.text = “data 1” select xxx;test <— Now has the listviewitem with “data 1” as string value..解决方法 要获取ListViewItem的枚举器,您必须投射ListView的Items集合: IEnumerable<ListViewItem> lv = listview1.items.Cast<ListViewItem>();

然后,您可以使用LINQ:

var test = from xxx in lv where xxx.text = “data 1” select xxx;