수업 010 (04.17 2020) Array - Burger
2020. 4. 17. 11:50
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[3];
arrIngredients[0] = new Ingredient("양파");
arrIngredients[1] = new Ingredient("베이컨");
arrIngredients[2] = new Ingredient("토마토");
Burger burger = new Burger("베이컨 토마토 버거", arrIngredients);
burger.PrintBurger();
}
}
}
|
2. Ingredients
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study._011_4
{
class Ingredient
{
public string name;
// 생성자
public Ingredient(string name)
{
this.name = name;
Console.WriteLine("재료 '{0}'이/(가) 생성되었습니다.", this.name);
}
}
}
|
3.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study._011_4
{
class Burger
{
public string name;
public Ingredient[] ingredients;
// 생성자
public Burger(string name, Ingredient[] ingredients)
{
this.name = name;
this.ingredients = ingredients;
}
public void PrintBurger()
{
Console.Write("{0}: ", this.name);
{
Console.Write("{0} ", ingredients[i].name);
}
Console.WriteLine();
Console.Write("{0}: ", this.name);
foreach (Ingredient ingredient in ingredients)
{
}
Console.WriteLine();
}
}
}
|
3. Result
728x90
'C# > Study' 카테고리의 다른 글
수업 010 (04.17 2020) Array (0) | 2020.04.17 |
---|---|
수업 010 (04.17 2020) Array - Food (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 |
수업 009 (04.16 2020) Array - Inventory (0) | 2020.04.16 |