using System.Collections.Generic;
public static void Main()
List<Animals> animalList = new List<Animals>()
new Animals() { AnimalType = "Lion", FoodRatio = 5, PreferredFood = "meat", FruitRatio = 5},
new Animals() { AnimalType = "Tiger", FoodRatio = 4 , PreferredFood = "meat", MeatRatio = 5 },
new Animals() { AnimalType = "Giraffe", FoodRatio = 3, PreferredFood = "fruit", FruitRatio = 2 },
new Animals() { AnimalType = "Piranha", FoodRatio = 5, PreferredFood = "fruit", MeatRatio = 2 },
new Animals() { AnimalType = "Piranha", FoodRatio = 5, PreferredFood = "meat", FruitRatio = 2 }
List<Prices> priceList = new List<Prices>()
new Prices() { FoodType = "meat", Price = 1000 },
new Prices() { FoodType = "fruit", Price = 2000 }
var totalCost = (from animal in animalList
on animal.PreferredFood equals price.FoodType
group new { Animal = animal, Price = price } by animal.AnimalType into g
Price = g.Sum(x => x.Price.Price * x.Animal.FruitRatio + x.Animal.MeatRatio * x.Price.Price)
Console.WriteLine(JsonConvert.SerializeObject(totalCost.ToList(), Formatting.Indented));
public string FoodType { get; set; }
public decimal Price { get; set; }
public string AnimalType { get; set; }
public decimal FoodRatio { get; set; }
public string PreferredFood { get; set; }
public string? OmnivoreMeatRatio { get; set; }
public decimal? MeatRatio { get; set; }
public decimal? FruitRatio { get; set; }