peter

peter

  • 0
  • 91
  • 0

Create a new List from two collections using LINQ expression

Apr 20 2021 5:12 PM
I want to return another List from two collections as shown. The task is to combine the two on VendorID and calculate a new price. The lists are not static and can enlarge in size.

IList<Product> CartList = new List<Product>() {
new Product() { VendorID = 1, Email = "John@yahoo", Price = 130,Name ="john" },
new Product() { VendorID = 1, Email = "john@yahoo", Price = 210,Name="john" },
new Product() { VendorID = 2, Email = "Bill@yahoo", Price = 180,Name ="Bill" },
new Product() { VendorID = 3, Email = "Ram@yahoo" , Price = 200,Name="Ram" }

};

IList<Funds> Funding = new List<Funds>() {
new Funds(){ VendorID = 1, Funds=30},
new Funds(){ VendorID = 2, Funds=40}

};

Result: Vendor     Email                          Price
               1           John@yahoo             310 (ie 340-30)
               2          Bill@yahoo             140 (ie 180-40)
               3          Ram@yahoo           200
 
 
 
 

Answers (6)