Created a class
public class DBClass: IDisposable
{
public string Name { get; set; }
public int Score { get; set; }
}
Used this class to create list of the class.
List<DBClass> dbc1 = new List<DBClass>();
List<DBClass> dbc2 = new List<DBClass>();
I have added two different set of data to the list. note : This is just an example
dbc1.Add(SetDBClass("A", 100));
dbc1.Add(SetDBClass("B", 100));
dbc1.Add(SetDBClass("C", 100));
dbc2.Add(SetDBClass("B", 200));
dbc2.Add(SetDBClass("C", 200));
dbc2.Add(SetDBClass("D", 200));
I need a List<DBClass>
object with the above two objects merged but in the below fashion.
A - 100 B - 300 C - 300 D - 200
How can the above be achieved by LINQ or any-other way ?
If you want to exclude the same data from both list then do as follows :
ParentDB.Where(b => !((from x in mainDataSource select x.Name).Contains(b.Name))).ToList();