读书人

linq IEnumerable Concat 步骤

发布时间: 2013-11-29 00:21:24 作者: rapoo

linq IEnumerable Concat 方法


var empList = new Dictionary<int,List<Employee>>();
Random r = new Random();
int length = 10000;

Console.WriteLine(string.Format("开始装载数据({0})...", length));
List<Employee> _List = new List<Employee>();
for (int i = 0; i < length; i++)
{
var e =new Employee()
{
ID = i,
FName = "A" + i,
Age = r.Next(0, 100),
Sex = r.Next(0, 2) == 1 ? 'F' : 'M'
};
if (empList.TryGetValue(e.Age, out _List))
_List.Add(e);
else
empList[e.Age] = new List<Employee>() { e };
}

IEnumerable<Employee> list = new List<Employee>();
List<Employee> list1 = new List<Employee>();
foreach (var item in empList)
{
IEnumerable<Employee> ie = item.Value.Where(p => p.Sex == 'F');
list1.AddRange(ie);
list.Concat(ie);
}

Console.WriteLine(list.ToList().Count);
Console.WriteLine(list1.Count);


如上是我的代码,运行结果中,list.Count 为0 ,list1.Count 有值。
我想问一下这是为什么?
小弟刚接触Linq,请大神解惑 Linq IEnumerale Concat
[解决办法]
本帖最后由 q107770540 于 2013-11-27 17:51:32 编辑 list = list.Concat(ie);

读书人网 >.NET

热点推荐