我想要做的是实际获取一组数据,然后按标识符对其进行分组,如下所示:
123456 123456 456789 456789 456789 135790
到
Name Quantity
123456 2
456789 3
135790 1
到目前为止我做了什么:
Foreach(string name in itemlist) //itemlist = 123456,123456... as mentioned above
{
var listitems= lvTest.Items.Cast<ListViewItem>;
bool exists = listitems.Where(item => item.Text == name).Any(); // to check if item name is already exists in list view
if (!exists)
{
ListViewItem lvItem = new ListViewItem(new string[] { name, "1" });
lvTest.Items.Add(lvItem);
}
else
{
ListViewItem lvItem = lvTest.Items.Cast<ListViewItem>.Where(item => item.Text == name).FirstOrDefault();
int count = (int)lvItem.SubItems[1].Text;
count = count + 1;
lvItem.SubItems[1].Text = count.ToString();
}
}
但由于问题而无法工作&#34;无法将方法组分配给隐式类型的局部变量&#34;在
行var listitems= lvTest.Items.Cast<ListViewItem>
请提前帮助和谢谢。
答案 0 :(得分:1)
var ex = {
category: {} // or you can initialize `name` here as well
} as example;
ex.category.name = 'electric';
答案 1 :(得分:1)
为什么不使用这样的东西,
List<string> lstString = new List<string> { "123456", "123456", "456789", "456789", "456789", "135790" };
var lstGroupList = lstString .GroupBy(item => item,
(key, group) => new { key, Items = group.ToList()}).ToList();