工作笔记之集合

原型:

 private List<Dictionary<string, string>> lstData = new List<Dictionary<string, string>>();

集合添加数据,重复的自动去掉

 

for (int i = 0; i < listView.Items.Count; i++)
                {
                    //获取list控件的集合
                    Dictionary<string, string> dicData = new Dictionary<string, string>();

                    dicData.Add(this.listView.Items[i].SubItems[2].Text, this.listView.Items[i].SubItems[3].Text);

                    if (lstData.Exists(x => {

                        foreach (var name in x.Keys)
                        {
                            if (name == this.listView.Items[i].SubItems[2].Text)
                            {
                                return true;
                            }
                        }
                        return false;})
                        )
                    {
                        continue;
                    }

                    lstData.Add(dicData);
                }

 

posted @ 2015-06-29 15:49  洛晨随风  阅读(145)  评论(0编辑  收藏  举报