Skip to content

Instantly share code, notes, and snippets.

@PhiHuyHoang
Last active October 3, 2018 18:44
Show Gist options
  • Save PhiHuyHoang/aeedb0919f55bbd4a5ff96a45e8e6ebc to your computer and use it in GitHub Desktop.
Save PhiHuyHoang/aeedb0919f55bbd4a5ff96a45e8e6ebc to your computer and use it in GitHub Desktop.
public class Food
{
private string name;
private int price;
private List<string> ingredient;
//Constructor
public Food(string name, int price, List<string> ingredient)
{
this.name = name;
this.price = price;
this.ingredient = ingredient;
}
public override string ToString()
{
return $"Food: {name}, Price: {price}" +
$" Ingredient: {String.Join(",", ingredient)}";
}
}
class Program
{
static void Main(string[] args)
{
List<Food> menu = new List<Food>();
Food C = new Food("Food C", 3000, new List<string> { "ingredient C", "ingredient D" });
Food D = new Food("Food D", 4000, new List<string> { "ingredient D", "ingredient E" });
menu.AddRange(new List<Food> { C, D });
foreach (Food f in menu)
{
Console.WriteLine(f.ToString());
}
Console.ReadLine();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment