수업 010 (04.17 2020) Array - Food
2020. 4. 17. 12:08
728x90
1. App
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study._011_4
{
class App
{
public App()
{
Ingredient[] arrIngredients = new Ingredient[2];
arrIngredients[0] = new Ingredient("밀가루 포대", 1);
arrIngredients[1] = new Ingredient("부드러운 양념", 1);
Food food = new Food("양념빵", arrIngredients);
food.PrintFood();
}
}
}
|
2. Ingredient
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study._011_4
{
class Ingredient
{
public string name;
public int amount;
// 생성자
public Ingredient(string name, int amount)
{
this.name = name;
this.amount = amount;
Console.WriteLine("재료 '{0}'이/(가) {1}개 생성되었습니다.", this.name, this.amount);
}
}
}
|
3. Food
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study._011_4
{
class Food
{
public string name;
public Ingredient[] ingredients;
public Food(string name, Ingredient[] ingredients)
{
this.name = name;
this.ingredients = ingredients;
}
public void PrintFood()
{
Console.Write("{0}: ", this.name);
{
Console.Write("{0} x {1} ", ingredients[i].name, ingredients[i].amount);
}
Console.WriteLine();
}
}
}
|
4. Result

728x90
'C# > Study' 카테고리의 다른 글
수업 011 (04.20 2020) 복습 - array (0) | 2020.04.20 |
---|---|
수업 010 (04.17 2020) Array (0) | 2020.04.17 |
수업 010 (04.17 2020) Array - Burger (0) | 2020.04.17 |
수업 010 (04.17 2020) Array - Product and price (0) | 2020.04.17 |
수업 009 (04.16 2020) Array - Inventory(2) (0) | 2020.04.16 |