回答編集履歴
2
コード修正
test
CHANGED
@@ -38,73 +38,77 @@
|
|
38
38
|
|
39
39
|
|
40
40
|
|
41
|
+
|
42
|
+
|
41
|
-
class
|
43
|
+
public class Test
|
42
44
|
|
43
45
|
{
|
44
46
|
|
45
|
-
|
47
|
+
|
46
48
|
|
47
|
-
|
49
|
+
class Report
|
48
|
-
|
49
|
-
public Report(string name,string value)
|
50
50
|
|
51
51
|
{
|
52
52
|
|
53
|
-
Name
|
53
|
+
public string Name { get; }
|
54
54
|
|
55
|
+
public string Value { get; }
|
56
|
+
|
57
|
+
public Report(string name,string value)
|
58
|
+
|
59
|
+
{
|
60
|
+
|
61
|
+
Name = name;
|
62
|
+
|
55
|
-
Value = value;
|
63
|
+
Value = value;
|
64
|
+
|
65
|
+
}
|
56
66
|
|
57
67
|
}
|
58
68
|
|
59
|
-
}
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
// Excelから読み込んだ結果のリストを返していると思って下さい
|
64
|
-
|
65
|
-
IEnumerable<Report> ReportsForTest()
|
69
|
+
private IEnumerable<Report> ReportsForTest()
|
66
|
-
|
67
|
-
{
|
68
|
-
|
69
|
-
yield return new Report("A", "1");
|
70
|
-
|
71
|
-
yield return new Report("B", "1");
|
72
|
-
|
73
|
-
yield return new Report("C", "2");
|
74
|
-
|
75
|
-
yield return new Report("D", "2");
|
76
|
-
|
77
|
-
yield return new Report("E", "3");
|
78
|
-
|
79
|
-
yield return new Report("F", "1");
|
80
|
-
|
81
|
-
yield return new Report("G", "4");
|
82
|
-
|
83
|
-
yield return new Report("H", "4");
|
84
|
-
|
85
|
-
yield return new Report("I", "5");
|
86
|
-
|
87
|
-
yield return new Report("J", "6");
|
88
|
-
|
89
|
-
}
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
void TestMethod1()
|
94
|
-
|
95
|
-
{
|
96
|
-
|
97
|
-
foreach(var xs in ReportsForTest().GroupBy(x => x.Value).Where(xs=>xs.Count()>1))
|
98
70
|
|
99
71
|
{
|
100
72
|
|
101
|
-
|
73
|
+
yield return new Report("A", "1");
|
102
74
|
|
75
|
+
yield return new Report("B", "1");
|
76
|
+
|
77
|
+
yield return new Report("C", "2");
|
78
|
+
|
79
|
+
yield return new Report("D", "2");
|
80
|
+
|
81
|
+
yield return new Report("E", "3");
|
82
|
+
|
83
|
+
yield return new Report("F", "1");
|
84
|
+
|
85
|
+
yield return new Report("G", "4");
|
86
|
+
|
87
|
+
yield return new Report("H", "4");
|
88
|
+
|
89
|
+
yield return new Report("I", "5");
|
90
|
+
|
91
|
+
yield return new Report("J", "6");
|
92
|
+
|
93
|
+
}
|
94
|
+
|
103
|
-
|
95
|
+
public void TestMethod1()
|
96
|
+
|
97
|
+
{
|
98
|
+
|
99
|
+
foreach (var xs in ReportsForTest().GroupBy(x => x.Value).Where(xs => xs.Count() > 1))
|
104
100
|
|
105
101
|
{
|
106
102
|
|
103
|
+
Console.WriteLine($"内容が重複しています:{xs.Key}");
|
104
|
+
|
105
|
+
foreach (var x in xs)
|
106
|
+
|
107
|
+
{
|
108
|
+
|
107
|
-
Console.WriteLine($"\t{x.Name}");
|
109
|
+
Console.WriteLine($"\t{x.Name}");
|
110
|
+
|
111
|
+
}
|
108
112
|
|
109
113
|
}
|
110
114
|
|
1
コード追加
test
CHANGED
@@ -17,3 +17,129 @@
|
|
17
17
|
|
18
18
|
|
19
19
|
こうすると、GroupByという名前そのままのメソッドがあるので、リストにそれを使うだけです。
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
VBで書くのが面倒なのでC#で書きます。
|
24
|
+
|
25
|
+
雰囲気だけ掴んで下さい。
|
26
|
+
|
27
|
+
なんだったらこれを機にC#を学びましょう。
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
```C#
|
32
|
+
|
33
|
+
using System;
|
34
|
+
|
35
|
+
using System.Collections.Generic;
|
36
|
+
|
37
|
+
using System.Linq;
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
class Report
|
42
|
+
|
43
|
+
{
|
44
|
+
|
45
|
+
public string Name { get; }
|
46
|
+
|
47
|
+
public string Value { get; }
|
48
|
+
|
49
|
+
public Report(string name,string value)
|
50
|
+
|
51
|
+
{
|
52
|
+
|
53
|
+
Name = name;
|
54
|
+
|
55
|
+
Value = value;
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
}
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
// Excelから読み込んだ結果のリストを返していると思って下さい
|
64
|
+
|
65
|
+
IEnumerable<Report> ReportsForTest()
|
66
|
+
|
67
|
+
{
|
68
|
+
|
69
|
+
yield return new Report("A", "1");
|
70
|
+
|
71
|
+
yield return new Report("B", "1");
|
72
|
+
|
73
|
+
yield return new Report("C", "2");
|
74
|
+
|
75
|
+
yield return new Report("D", "2");
|
76
|
+
|
77
|
+
yield return new Report("E", "3");
|
78
|
+
|
79
|
+
yield return new Report("F", "1");
|
80
|
+
|
81
|
+
yield return new Report("G", "4");
|
82
|
+
|
83
|
+
yield return new Report("H", "4");
|
84
|
+
|
85
|
+
yield return new Report("I", "5");
|
86
|
+
|
87
|
+
yield return new Report("J", "6");
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
void TestMethod1()
|
94
|
+
|
95
|
+
{
|
96
|
+
|
97
|
+
foreach(var xs in ReportsForTest().GroupBy(x => x.Value).Where(xs=>xs.Count()>1))
|
98
|
+
|
99
|
+
{
|
100
|
+
|
101
|
+
Console.WriteLine($"内容が重複しています:{xs.Key}");
|
102
|
+
|
103
|
+
foreach(var x in xs)
|
104
|
+
|
105
|
+
{
|
106
|
+
|
107
|
+
Console.WriteLine($"\t{x.Name}");
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
```
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
TestMethod1の実行結果:
|
122
|
+
|
123
|
+
```
|
124
|
+
|
125
|
+
内容が重複しています:1
|
126
|
+
|
127
|
+
A
|
128
|
+
|
129
|
+
B
|
130
|
+
|
131
|
+
F
|
132
|
+
|
133
|
+
内容が重複しています:2
|
134
|
+
|
135
|
+
C
|
136
|
+
|
137
|
+
D
|
138
|
+
|
139
|
+
内容が重複しています:4
|
140
|
+
|
141
|
+
G
|
142
|
+
|
143
|
+
H
|
144
|
+
|
145
|
+
```
|