前言
在Dotnet开发过程中,Concat作为IEnumerable的扩展方法,十分常用。本文对Concat方法的关键源码进行简要分析,以方便大家日后更好的使用该方法。
使用
Concat 连接两个序列。
假如我们有这样的两个集合,我们需要把两个集合进行连接!
List<string> lst = new List<string> { "张三", "李四" };
List<string> lst2 = new List<string> { "王麻子" };
-
不使用Linq
大概会这样写!
private List<string> Concat(List<string> first, List<string> second)
{
if (first == null)
{
throw new Exception("first is null");
}
if (second == null)
{
throw new Exception("second is null");
}
List<string> lstAll = new List<string>();
foreach (var item in f