如何从IEnumerable中提取数据?



我正在用c#编码。我有这段代码,告诉我在我的2 listview的数据的差异。

var diff = ListViewDatabase.Items.Cast<ListViewItem>()
                           .Select(x => x.SubItems[1].Text)
                           .Except(LstView.Items.Cast<ListViewItem>()
                           .Select(x => x.SubItems[1].Text));
MessageBox.Show(string.Format("{0} Missing.", string.Join(",", diff), "n"));

现在我如何从变量diff提取信息到单个字符串?它需要被分隔成不同的字符串。

您似乎想要将这些条目连接成一个逗号分隔的字符串。

试试这个:

result = diff.Aggregate(result, (current, item) => current + string.Format("{0},", item));
MessageBox(string.Format("List duplicates: {0}", result.TrimEnd(Convert.ToChar(","));

最新更新