回答編集履歴

3

修正

2018/02/26 09:31

投稿

Zuishin
Zuishin

スコア28662

test CHANGED
@@ -18,7 +18,7 @@
18
18
 
19
19
 
20
20
 
21
- class Customer
21
+ class Customer : ICustomer
22
22
 
23
23
  {
24
24
 

2

修正

2018/02/26 09:30

投稿

Zuishin
Zuishin

スコア28662

test CHANGED
@@ -72,25 +72,41 @@
72
72
 
73
73
  ```C#
74
74
 
75
- Dictionary<string, Action<Customer>> customerList = new Dictionary<string, Action<Customer>>()
75
+ List<string> Ids = new List<string>()
76
76
 
77
77
  {
78
78
 
79
- { "customer1", customer => { Console.WriteLine("私は customer1"); } },
79
+ "customer1", "customer2", "customer3"
80
-
81
- { "customer2", customer => { Console.WriteLine("私は customer1 ではなく customer2"); } },
82
-
83
- { "customer3", customer => { Console.WriteLine("私は customer3 のような気がする"); } },
84
80
 
85
81
  };
86
82
 
83
+
84
+
87
- foreach (var id in customerList.Keys)
85
+ var customer1 = new Customer(Ids[0], customer =>
88
86
 
89
87
  {
90
88
 
91
- new Customer(id, customerList[id]);
89
+ Console.WriteLine("私は customer1");
92
90
 
93
- }
91
+ });
92
+
93
+ var customer2 = new Customer(Ids[1], customer =>
94
+
95
+ {
96
+
97
+ Console.WriteLine("私は customer2");
98
+
99
+ });
100
+
101
+ var customer3 = new Customer(Ids[2], customer =>
102
+
103
+ {
104
+
105
+ Console.WriteLine("私は customer3");
106
+
107
+
108
+
109
+ });
94
110
 
95
111
  ```
96
112
 
@@ -102,6 +118,6 @@
102
118
 
103
119
  ```C#
104
120
 
105
- Console.WriteLine(customerList.Keys.Distinct().Count() == customerList.Count() ? "重複はありません" : "重複がありました");
121
+ Console.WriteLine(Ids.Distinct().Count() == Ids.Count() ? "重複はありません" : "重複がありました");
106
122
 
107
123
  ```

1

修正

2018/02/26 09:28

投稿

Zuishin
Zuishin

スコア28662

test CHANGED
@@ -72,19 +72,23 @@
72
72
 
73
73
  ```C#
74
74
 
75
- List<string> Ids = new List<string>()
75
+ Dictionary<string, Action<Customer>> customerList = new Dictionary<string, Action<Customer>>()
76
76
 
77
77
  {
78
78
 
79
- "customer1", "customer2", "customer3"
79
+ { "customer1", customer => { Console.WriteLine("私は customer1"); } },
80
+
81
+ { "customer2", customer => { Console.WriteLine("私は customer1 ではなく customer2"); } },
82
+
83
+ { "customer3", customer => { Console.WriteLine("私は customer3 のような気がする"); } },
80
84
 
81
85
  };
82
86
 
83
- foreach (var id in Ids)
87
+ foreach (var id in customerList.Keys)
84
88
 
85
89
  {
86
90
 
87
- new Customer(id, customer => { });
91
+ new Customer(id, customerList[id]);
88
92
 
89
93
  }
90
94
 
@@ -92,4 +96,12 @@
92
96
 
93
97
 
94
98
 
95
- Ids 重複をチェックすればいいと思います。
99
+ ようにチェックできます。
100
+
101
+
102
+
103
+ ```C#
104
+
105
+ Console.WriteLine(customerList.Keys.Distinct().Count() == customerList.Count() ? "重複はありません" : "重複がありました");
106
+
107
+ ```