현재 교육받고 있는 학원에서 강사님이 좋은 제도를 만드셔서,
복습도 할겸 만들어본 메서드반환 문제입니다.
카페에 업로드한 것과 동일합니다.
문제의 요지는 아이템리스트 컬렉션 객체와 실체화된 이름 컬렉션 객체, 수량 컬렉션 객체가 있습니다.
메서드를 이용해 아이템리스트 컬렉션 객체안에 값을넣어 실체화 시켜주세요.
-----------------------------------------------------------------------------------------------------------------------------------
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Question_2
{
class ItemData
{
public string name;
public int amount;
public ItemData(string name, int amount)
{
this.name = name;
this.amount = amount;
}
}
class App
{
List<ItemData> ItemDatasList;
List<string> itemNameList;
List<int> itemAmountList;
public App()
{
itemNameList = new List<string>();
itemNameList.Add("김밥");
itemNameList.Add("순대");
itemAmountList = new List<int>();
ItemDatasList = this.AdditemDataList(itemNameList,itemAmountList);
foreach (ItemData element in ItemDatasList)
{
}
}
public List<ItemData> AdditemDataList(List<string> itemNameList, List<int> itemAmountList)
{
List<ItemData> newItemDataList = new List<ItemData>();
{
ItemData itemData = new ItemData(itemNameList[i], itemAmountList[i]);
}
return newItemDataList;
}
}
}
|
-----------------------------------------------------------------------------------------------------------------------------------
출력값
-----------------------------------------------------------------------------------------------------------------------------------
'C# > 복습' 카테고리의 다른 글
2020-04-25 업적 시스템 복습(2) && 생각정리 (0) | 2020.04.25 |
---|---|
2020-04-25 업적시스템 복습 & 생각정리 1 (0) | 2020.04.25 |
메서드반환 문제 1 (0) | 2020.04.21 |
백준 알고리즘 단계별 문제-For문 출력값 (0) | 2020.04.05 |
백준 알고리즘 단계별 문제-For문 Source (0) | 2020.04.05 |