[Solved] Copy certain properties from two lists into third list [closed]


First: refering to a class and a list with the same name is confusing. I reference to them as listA and class A

This is not possible without listA and listB sharing a property to merge them on.

If class B consisted of {id, gender, level} where id was the same as id from class A you could do:

var bDic = listB.ToDictionary(a => a.id, a => a); // for faster searching
var listC = listA.Select(a => new C()
{
   id = a.id,
   name = a.name,
   status = a.status,
   gender = bDic[a.id].gender,
   level = bDic[a.id].level,
}
.ToList();

2

solved Copy certain properties from two lists into third list [closed]