Linq 连接运算符:Concat,Union



//Concat()方法附加两个相同类型的序列,并返回一个新序列(集合)
IList<string> strList = new List<string>() { "One", "Two", "Three", "Four", "Five" }; IList<string> str1List = new List<string>() { "One", "Two", "Three", "Four", "Five" }; IEnumerable<string> newlist = strList.Concat(str1List); newlist.ToList().ForEach(f => Console.Write(f + ","));
//显示结果为:  One,Two,Three,Four,Five,One,Two,Three,Four,Five,

 

原来还有这种写法,自己还记了笔记的.悲哀!

一直以来,我都是这样写的:

                var list = new List<string>();
                list.AddRange(strList);
                list.AddRange(str1List);

哎,悲哀!

 

Union 和 Concat 不一样的地方是它要去重

posted @ 2017-12-30 21:13  热敷哥  阅读(671)  评论(0编辑  收藏  举报