-----------------------------------------------------------------------------------------------------------------------------------
ItemData Class
-----------------------------------------------------------------------------------------------------------------------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Repeat_013
{
enum eItemType
{
Weapon,
Armor,
Accessory,
}
enum eGrade
{
Normal,
Rare,
Epic,
Legend,
}
class ItemData
{
public int id;
public eItemType item_type;
public string name;
public eGrade grade;
public int damage;
public int armor;
}
}
|
-----------------------------------------------------------------------------------------------------------------------------------
App Class
-----------------------------------------------------------------------------------------------------------------------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
namespace Repeat_013
{
class App
{
public App()
{
string json = File.ReadAllText(path);
ItemData[] arrItemDatas = JsonConvert.DeserializeObject<ItemData[]>(json);
Dictionary<int, ItemData> dicItemDatas = new Dictionary<int, ItemData>();
foreach (ItemData data in arrItemDatas)
{
}
//foreach (KeyValuePair<int, ItemData> pair in dicItemDatas)
//{
// ItemData data = pair.Value;
// Console.WriteLine("{0} {1}", data.id, data.name);
//}
foreach (KeyValuePair<int, ItemData> pair in dicItemDatas)
{
Console.WriteLine("id : {0}\nitem_type : {1}\nname : {2}\ngrade : {3}\ndamage : {4}\narmor : {5}",
Console.WriteLine("-------------------------------");
}
}
}
}
|
-----------------------------------------------------------------------------------------------------------------------------------
출력값
-----------------------------------------------------------------------------------------------------------------------------------


-----------------------------------------------------------------------------------------------------------------------------------
※주의할점
1. 바인딩(맵핑)클래스를 만들었을 때, 엑셀의 컬럼명과 맴버 변수 명을 동일하게 해야한다.
2. 메인에 new App()적는거 잊지 말자..(대체왜안되지하면서 15분동안 삽질했는데, 알고보니 메인에 new App()을 안함...)
'C# > 과제' 카테고리의 다른 글
2020-05-03 2048게임 과제 진행중 (0) | 2020.05.03 |
---|---|
2020-04-17 과제 (0) | 2020.04.19 |
2020-04-14 과제 (0) | 2020.04.15 |
2020-04-10 과제 완료. Source code (0) | 2020.04.12 |
2020-04-10 과제 문제 및 진행단계 기록 (0) | 2020.04.10 |