|
/실습 2019. 10. 17. 15:27
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
|
using System;
using System.Collections.Generic;
namespace Syntax043
{
public class Champion
{
public string name;
public int damage;
public Champion()
{
//생성자
}
public virtual void Attack(Champion target)
{
}
public void Hit(int damage)
{
}
}
}
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
using System;
using System.Collections.Generic;
namespace Syntax043
{
public class Ashe : Champion
{
public Ashe()
{
}
public override void Attack(Champion target)
{
}
}
}
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Syntax043
{
public class Garen : Champion
{
public Garen()
{
}
public override void Attack(Champion target)
{
Console. WriteLine( this.name + "이 검을 휘두르며" + target.name + "을 공격합니다.");
base.Attack(target);
}
}
}
|
|
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Syntax043
{
public class App
{
public App()
{
Ashe ashe = new Ashe();
Garen garen = new Garen();
}
}
}
|
|
/실습 2019. 10. 16. 14:29
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Syntax042
{
public class App
{
public App()
{
Console.WriteLine("Hello World!");
//컬렉션 선언
Dictionary<int, ItemData> dicItemData;
//컬렉션 객체 생성
dicItemData = new Dictionary<int, ItemData>();
//데이터들 객체 새성
var data1 = new ItemData(100, "장검",0,"sword_00");
var data2 = new ItemData(200, "가죽옷",0,"leather_clothes_00");
var data3 = new ItemData(300, "체력물약",1,"health_potion_00");
var data4 = new ItemData(400, "금괴",2,"gold_bars_00");
//딕셔너리에 추가 (키:값)
//검색 : 키값이 100인 itemData
var foundData = dicItemData[100]; //값 : itemData
//삭제 : 키값이 200인 itemData를 컬렉션에서 제거
//출력
foreach (KeyValuePair<int, ItemData> pair in dicItemData)
{
//키 : 아이템의 id
//값 : ItemData
}
}
}
}
|
|
/실습 2019. 10. 15. 16:48
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Syntax039
{
public class App
{
public App()
{
//Dictionary : 키 , 값의 컬렉션
//컬렉션 선언
Dictionary<int, string> dicUsers;
//컬렉션 인스턴스 생성
dicUsers = new Dictionary<int, string>();
//값 추가
//값 제거
if (isRemoved)
{
Console.WriteLine("제거 되었습니다.");
}
else
{
Console.WriteLine("키값을 찾을수 없어 제거 하지 못했습니다.");
}
//출력
foreach (KeyValuePair<int, string> pair in dicUsers)
{
}
//검색
Console.WriteLine(dicUsers[850516]);
}
}
}
|
|
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Syntax040
{
public class App
{
public App()
{
//도감번호 / 몬스터
// 이름, 공격력, 타입
//Dictionary 컬렉션 선언
Dictionary<int, Monster> dicMonster;
//컬렉션 인스턴스 생성
dicMonster = new Dictionary<int, Monster>();
//데이터 추가
var mon1 = new Monster(1001, "이상해씨", 13, 11);
var mon2 = new Monster(1002, "피카츄", 17, 08);
//데이터 검색
var foundMon = dicMonster[1001];
//데이터 삭제
//데이터 출력
foreach (KeyValuePair<int, Monster> pair in dicMonster)
{
}
}
}
}
|
|
Console/과제 2019. 10. 14. 15:28
/실습 2019. 10. 14. 15:24
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Syntax031
{
public class App
{
public App()
{
Console.WriteLine("2019-10-14");
int[] arr = new int[5];
arr[0] = 1;
Console.WriteLine(arr[1]); //0
Console.WriteLine(arr[6]);
List<int> List = new List<int>();
Console.WriteLine(List.Count); //0
List.Add(1);
Console.WriteLine(List[1]); //0
Console.WriteLine(List[List.Count - 1]); //1
}
}
}
|
|
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Syntax032
{
public class App
{
public App()
{
//배열
Product[] arrProducts = new Product[5];
//추가
arrProducts[0] = new Product("가방", 15000);
arrProducts[1] = new Product("원피스", 18000);
//삭제
arrProducts[0] = null;
Product foundProduct = null;
string searchProductName = "원피스";
//검색
{
//for문을돌면서 인덱스로 배열의 요소에 접근
//Product객체 참조 또는 null
Product product = arrProducts[i];
{
foundProduct = product;
}
}
if (foundProduct == null)
{
Console.WriteLine("{0}을(를) 찾지 못했습니다.", searchProductName);
}
else
{
}
}
}
}
|
|
/실습 2019. 10. 11. 11:35
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Syntax030
{
public class App
{
public App()
{
Console.WriteLine("2019-10-11");
//Product개채들을 관리 하기 위해 컬렉션 List 클래스의 인스턴스를 생성함.
List<Product> productList = new List<Product>();
//Product개체를 만듬
Product p1 = new Product("운동화", 2500);
Product p2 = new Product("후드티", 3300);
//리스트에 추가
//리스트 요소 출력
DisplayProducts();
//리스트 요소 제거
Console.WriteLine("succes: {0}", success);
//리스트 요소 출력
DisplayProducts();
//리스트 요소들의 갯수 출력
//인덱스 접근
Console.WriteLine("----> " + productList[0].name);
}
public void DisplayProducts()
{
//리스트 요소 출력
Product product = productList[i];
}
}
}
}
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Syntax030
{
public class Product
{
public int cost;
public string name;
public Product(string name, int cost)
{
}
}
}
|
|
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
59
60
61
62
63
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Syntax030
{
public class App
{
public List<Product> productList;
public App()
{
Console.WriteLine("2019-10-11");
//product개채들을 관리 하기 위해 컬렉션 List 클래스의 인스턴스를 생성함.
productList = new List<Product>();
//Product개체를 만듬
Product p1 = new Product("운동화", 2500);
//리스트에 추가
//리스트 요소 출력
DisplayProducts();
//Product개체 생성
Product p2 = new Product("후드티", 3300);
//리스트에 추가
//리스트 요소 출력
DisplayProducts();
//리스트 요소 제거
Console.WriteLine("succes: {0}", success);
//리스트 요소 출력
DisplayProducts();
//리스트 요소들의 갯수 출력
//인덱스 접근
Console.WriteLine("---->" + productList[0].name);
}//end of App
public void DisplayProducts()
{
//리스트 요소 출력
{
Product product = productList[i];
}
}
}
}
|
|
/실습 2019. 10. 10. 16:26
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Syntax027
{
public class app
{
//배열선언
product[] arrProducts;
public app()
{
Console.WriteLine("2019-10-10");
//배열초기화
arrProducts = new product[5];
//객체 생성
var product1 = new product(2500, "운동화");
//배열에 추가
arrProducts[0] = product1;
arrProducts[1] = new product(3300, "후드티");
//배열의 요소 출력
Displayproducts();
//배열의 요소중 가격이 2500원인 것 찾기
//배열의 모든 요소를 반복하면서 찾는다.
//요소중 가격이 2500인것을 찾는다.
{
}
foreach (var product in arrProducts)
{
}
int k = 0;
while (true)
{
{
break;
}
k++;
}
}
public void Displayproducts()
{
foreach (product product in arrProducts)
{
if (product != null)
}
//int[] arrcost = new int[5];
//string[] arrNames = new string[5];
//arrcost[0] = 2500;
//arrNames[0] = "운동화";
//arrcost[1] = 3300;
//arrNames[1] = "후드티";
////
//// int cost = arrcost[i];
//// string name = arrNames[i];
//// Console.WriteLine("{0}:{1}원", name, cost);
//int i = 0;
//foreach (int cost in arrcost)
//{
// string name = arrNames[i];
// Console.WriteLine("{0}:{1}원", name, cost);
// i++;
//}
}
}
}
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Syntax027
{
public class product
{
public int cost;
public string name;
//생성자
public product(int cost, string name)
{
this.cost = cost;
this.name = name;
}
}
}
|
|
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Syntax028
{
public class inventory
{
public item[] arritems;
public int idx;
public inventory()
{
this.arritems = new item[5];
}
public void Additem(item item)
{
this.arritems[idx++] = item;
}
public item Finditembyname(string name)
{
{
item item = arritems[i];
{
{
return item;
}
}
}
return null;
}
}
}
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Syntax028
{
public class item
{
public int id;
public string name;
public item(int id, string name)
{
this.id = id;
this.name = name;
}
}
}
|
|
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Syntax028
{
public class App
{
public App()
{
inventory inventory = new inventory();
inventory.Additem(new item(100, "장검"));
inventory.Additem(new item(200, "단검"));
item item = inventory.Finditembyname("장검");
if (item == null)
{
Console.WriteLine("아이템 검색실패");
}
else
{
}
}
}
}
|
|
/실습 2019. 10. 8. 11:51
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Syntax024
{
public class App
{
public App()
{
int[] arr = new int[5];
{
Console.WriteLine(arr[i]);
}
}
}
}
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Syntax024
{
public class App
{
public App()
{
float[] arr = new float[5];
arr[0] = 3.14f;
{
Console.WriteLine(arr[i]);
}
}
}
}
|
|
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Syntax024
{
public class App
{
public App()
{
Pizza[] arr = new Pizza[5];
arr[0] = new Pizza("고르곤졸라");
arr[1] = new Pizza("꿈을피자");
arr[2] = new Pizza("쉬림프피자");
arr[3] = new Pizza("단호박골드피자");
arr[4] = new Pizza("치즈피자");
{
Pizza pizza = arr[i];
Console.WriteLine(arr[i]);
}
}
}
}
|
|
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Syntax025
{
public class App
{
public App()
{
string[] arritemNames = new string[5];
arritemNames[0] = "장검";
arritemNames[1] = "단검";
arritemNames[2] = "활";
arritemNames[3] = "도끼";
arritemNames[4] = "창";
Item[] arritems = new Item[5];
{
arritems[i] = new Item(arritemNames[i]);
}
}
}
}
|
|
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Syntax026
{
class inventory
{
public item[] items;
public int itemindex;
public inventory()
{
this.items = new item[5];
}
public void Additem(item item)
{
this.items[itemindex] = item;
itemindex++;
}
public void GetItem(string itemName)
{
{
if(this.items[i].name == itemName)
{
break;
}
}
return founditem
}
}
}
|
|
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Syntax026
{
public class App
{
public App()
{
inventory inventory = new inventory();
inventory.Additem(new item("장검"));
inventory.Additem(new item("단검"));
inventory.Additem(new item("활"));
inventory.Additem(new item("도끼"));
inventory.Additem(new item("창"));
item founditem = inventory.GetItem("단검");
if (founditem != null)
{
}
else
{
Console.WriteLine("아이템을 찾을수 없습니다.");
}
}
}
}
|
|
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Syntax026
{
public class inventory
{
public item[] items;
public int itemindex;
public inventory()
{
this.items = new item[5];
}
public void Additem(item item)
{
this.items[itemindex] = item;
itemindex++;
}
public item GetItem(string itemName)
{
item founditem = null;
{
if(this.items[i].name == itemName)
{
break;
}
}
return founditem;
}
}
}
|
|
|