[c#] Dictionary practice2
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
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication5
{
class Student
{
public string Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public Student(string id, string name, string address)
{
Id = id;
Name = name;
Address = address;
}
}
class Score
{
public int Math { get; set; }
public int Korean { get; set; }
public int English { get; set; }
public int Science { get; set; }
public Score(int math, int korean, int english, int science)
{
Math = math;
Korean = korean;
English = english;
Science = science;
}
}
class Program
{
static void Main(string[] args)
{
var score_list = new Dictionary<Student, Score>();
score_list.Add(new Student("001", "KIM", "Seoul"), new Score(60, 80, 30, 50));
score_list.Add(new Student("002", "SIM", "Deagu"), new Score(65, 90, 10, 60));
score_list.Add(new Student("003", "JOO", "Deagu"), new Score(80, 70, 50, 70));
score_list.Add(new Student("004", "LIM", "Deagu"), new Score(90, 50, 70, 80));
score_list.Add(new Student("005", "YOU", "Seoul"), new Score(70, 12, 90, 90));
foreach (KeyValuePair<Student, Score> a in score_list)
{
Console.WriteLine("ID:{0}, NAME:{1}, ADDRESS:{2} --> MATH:{3}, KOREAN:{4}, ENGLISH:{5}",
a.Key.Id.ToString(),
a.Key.Name.ToString(),
a.Key.Address.ToString(),
a.Value.Math.ToString(),
a.Value.Korean.ToString(),
a.Value.English.ToString());
}
System.Console.ReadLine();
}
}
}
| cs |
댓글
댓글 쓰기