在List< string>中添加操作 [英] Add operation in List<string>
本文介绍了在List< string>中添加操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
使用linq合并两个对象列表
Possible Duplicate:
Merge two object lists with linq
我有2个string
类型的Lists
:
List1 has items - item1, item2, item3
List2 has items - item1, item4, item5
现在,我需要比较两个lists
,并将List2
中缺少的内容添加到List1
中.修改后的List1
将是
Now I need to compare both lists
and add the missing ones from List2
into List1
. The modified List1
will be
list 1 : item1, item2, item3, item4, item5
推荐答案
您可以为此使用LiNQ
:
List<string> newList = List1.Union(List2).ToList();
这篇关于在List< string>中添加操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文