You need a way to associate the inventory level of the ingredients (which you have as your double variables), with the order id of the ingredient (which is the result you want at the end).
One solution would be to use an Ingredient class that might look something like this:
public class Ingredient
{
public double InventoryLevel { get; set; }
public string OrderId { get; set; }
}
Then you could have a list of ingredients, rather than doubles, order them by their inventory level, and get the lowest stocked ingredient.
// make your list of ingredients with order ids, and inventory levels
var ingredients = new List<Ingredient>
{
new Ingredient {OrderId = "Ingredient1", InventoryLevel = 10.0},
new Ingredient {OrderId = "Ingredient2", InventoryLevel = 2.0},
new Ingredient {OrderId = "Ingredient3", InventoryLevel = 15.0},
new Ingredient {OrderId = "Ingredient4", InventoryLevel = 6.0}
};
// get the ingredient with the lowest inventory level
var lowestStockedIngredient = ingredients.OrderBy(i => i.InventoryLevel ).FirstOrDefault();
string orderId = lowestStockedIngredient.OrderId;
3
solved Given a list of named doubles, return the name of the variable with the lowest value [closed]