수업 012 (04.21 2020) List<> add, remove, enum
2020. 4. 21. 11:19
728x90
1. App.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study._013_2
{
class App
{
public App()
{
List<Item> herbBags = new List<Item>();
HerbBag herbBag = new HerbBag();
herbBag.AddItem(item1);
herbBag.AddItem(item2);
herbBag.RemoveItem("물망초");
}
}
}
|
2. HerbBag.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study._013_2
{
class HerbBag
{
public int sellPrice;
public List<Item> itemList;
// 생성자
public HerbBag()
{
this.sellPrice = 2500;
this.itemList = new List<Item>();
}
public void AddItem(Item item)
{
{
return;
}
else
{
{
}
else
{
}
}
}
public void RemoveItem(string name)
{
{
if (itemList[i].name == name)
{
Console.WriteLine("{0}를 가방에서 뺐습니다. \n", itemList[i].name);
}
else
{
Console.WriteLine("{0}을 뺄 수 없습니다. \n", itemList[i].name);
}
}
}
}
}
|
3. Item.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study._013_2
{
public enum eItemType
{
Herb,
Potion,
Weapon
}
class Item
{
public string name;
public eItemType itemType;
// 생성자
public Item(string name, eItemType itemType)
{
this.name = name;
this.itemType = itemType;
}
}
}
|
4. Result

728x90
'C# > Study' 카테고리의 다른 글
수업 013 (04.22 2020) 복습 - dictionary<Tkey, TValue> (0) | 2020.04.22 |
---|---|
수업 012 (04.21 2020) List<> HerbBag (0) | 2020.04.22 |
수업 012 (04.21 2020) List<> 복습 (0) | 2020.04.21 |
수업 011 (04.20 2020) List<> (0) | 2020.04.21 |
수업 011 (04.20 2020) 복습 - array (0) | 2020.04.20 |