728x90
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
namespace Study09
{
class App
{
//생성자
public App()
{
Console.WriteLine("App");
Inventory<Weapon> inventory = new Inventory<Weapon>(10);
inventory.AddItem(new Weapon());
Inventory<Armor> inventory1 = new Inventory<Armor>(10);
inventory1.AddItem(new Armor());
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study09
{
class Inventory<T>
{
public T[] equipments;
int index = 0;
//생성자
public Inventory(int capacity)
{
//배열 초기화(인스턴스화)
this.equipments = new T[capacity];
}
public void AddItem(T item)
{
this.equipments[this.index++] = item;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study09
{
class Weapon
{
//무기 관리를 위한 배열
//생성자
public Weapon()
{
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study09
{
class Armor
{
//방어구 관리를 위한 배열
//생성자
public Armor()
{
}
}
}
728x90
'C# > 수업내용' 카테고리의 다른 글
[ C# 8일차 ] 오버라이딩 (0) | 2023.01.10 |
---|---|
[ C# 8일차 ] Collection 연습_List, Queue, Stack (0) | 2023.01.10 |
[ C# 8일차 ] Generic 일반화 메서드 (0) | 2023.01.10 |
[ C# 8일차 ] Struct 구조체 (0) | 2023.01.10 |
[ C# 8일차 ] Collections_Hashtable (0) | 2023.01.10 |