回答編集履歴
2
コード修正
answer
CHANGED
@@ -18,40 +18,42 @@
|
|
18
18
|
using System.Collections.Generic;
|
19
19
|
using System.Linq;
|
20
20
|
|
21
|
+
|
21
|
-
class
|
22
|
+
public class Test
|
22
23
|
{
|
24
|
+
|
23
|
-
|
25
|
+
class Report
|
24
|
-
public string Value { get; }
|
25
|
-
public Report(string name,string value)
|
26
26
|
{
|
27
|
+
public string Name { get; }
|
28
|
+
public string Value { get; }
|
29
|
+
public Report(string name,string value)
|
30
|
+
{
|
27
|
-
|
31
|
+
Name = name;
|
28
|
-
|
32
|
+
Value = value;
|
33
|
+
}
|
29
34
|
}
|
30
|
-
}
|
31
|
-
|
32
|
-
// Excelから読み込んだ結果のリストを返していると思って下さい
|
33
|
-
IEnumerable<Report> ReportsForTest()
|
35
|
+
private IEnumerable<Report> ReportsForTest()
|
34
|
-
{
|
35
|
-
yield return new Report("A", "1");
|
36
|
-
yield return new Report("B", "1");
|
37
|
-
yield return new Report("C", "2");
|
38
|
-
yield return new Report("D", "2");
|
39
|
-
yield return new Report("E", "3");
|
40
|
-
yield return new Report("F", "1");
|
41
|
-
yield return new Report("G", "4");
|
42
|
-
yield return new Report("H", "4");
|
43
|
-
yield return new Report("I", "5");
|
44
|
-
yield return new Report("J", "6");
|
45
|
-
}
|
46
|
-
|
47
|
-
void TestMethod1()
|
48
|
-
{
|
49
|
-
foreach(var xs in ReportsForTest().GroupBy(x => x.Value).Where(xs=>xs.Count()>1))
|
50
36
|
{
|
51
|
-
|
37
|
+
yield return new Report("A", "1");
|
38
|
+
yield return new Report("B", "1");
|
39
|
+
yield return new Report("C", "2");
|
40
|
+
yield return new Report("D", "2");
|
41
|
+
yield return new Report("E", "3");
|
42
|
+
yield return new Report("F", "1");
|
43
|
+
yield return new Report("G", "4");
|
44
|
+
yield return new Report("H", "4");
|
45
|
+
yield return new Report("I", "5");
|
46
|
+
yield return new Report("J", "6");
|
47
|
+
}
|
52
|
-
|
48
|
+
public void TestMethod1()
|
49
|
+
{
|
50
|
+
foreach (var xs in ReportsForTest().GroupBy(x => x.Value).Where(xs => xs.Count() > 1))
|
53
51
|
{
|
52
|
+
Console.WriteLine($"内容が重複しています:{xs.Key}");
|
53
|
+
foreach (var x in xs)
|
54
|
+
{
|
54
|
-
|
55
|
+
Console.WriteLine($"\t{x.Name}");
|
56
|
+
}
|
55
57
|
}
|
56
58
|
}
|
57
59
|
}
|
1
コード追加
answer
CHANGED
@@ -7,4 +7,67 @@
|
|
7
7
|
内容を.Value
|
8
8
|
としておきます。
|
9
9
|
|
10
|
-
こうすると、GroupByという名前そのままのメソッドがあるので、リストにそれを使うだけです。
|
10
|
+
こうすると、GroupByという名前そのままのメソッドがあるので、リストにそれを使うだけです。
|
11
|
+
|
12
|
+
VBで書くのが面倒なのでC#で書きます。
|
13
|
+
雰囲気だけ掴んで下さい。
|
14
|
+
なんだったらこれを機にC#を学びましょう。
|
15
|
+
|
16
|
+
```C#
|
17
|
+
using System;
|
18
|
+
using System.Collections.Generic;
|
19
|
+
using System.Linq;
|
20
|
+
|
21
|
+
class Report
|
22
|
+
{
|
23
|
+
public string Name { get; }
|
24
|
+
public string Value { get; }
|
25
|
+
public Report(string name,string value)
|
26
|
+
{
|
27
|
+
Name = name;
|
28
|
+
Value = value;
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
// Excelから読み込んだ結果のリストを返していると思って下さい
|
33
|
+
IEnumerable<Report> ReportsForTest()
|
34
|
+
{
|
35
|
+
yield return new Report("A", "1");
|
36
|
+
yield return new Report("B", "1");
|
37
|
+
yield return new Report("C", "2");
|
38
|
+
yield return new Report("D", "2");
|
39
|
+
yield return new Report("E", "3");
|
40
|
+
yield return new Report("F", "1");
|
41
|
+
yield return new Report("G", "4");
|
42
|
+
yield return new Report("H", "4");
|
43
|
+
yield return new Report("I", "5");
|
44
|
+
yield return new Report("J", "6");
|
45
|
+
}
|
46
|
+
|
47
|
+
void TestMethod1()
|
48
|
+
{
|
49
|
+
foreach(var xs in ReportsForTest().GroupBy(x => x.Value).Where(xs=>xs.Count()>1))
|
50
|
+
{
|
51
|
+
Console.WriteLine($"内容が重複しています:{xs.Key}");
|
52
|
+
foreach(var x in xs)
|
53
|
+
{
|
54
|
+
Console.WriteLine($"\t{x.Name}");
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}
|
58
|
+
```
|
59
|
+
|
60
|
+
|
61
|
+
TestMethod1の実行結果:
|
62
|
+
```
|
63
|
+
内容が重複しています:1
|
64
|
+
A
|
65
|
+
B
|
66
|
+
F
|
67
|
+
内容が重複しています:2
|
68
|
+
C
|
69
|
+
D
|
70
|
+
内容が重複しています:4
|
71
|
+
G
|
72
|
+
H
|
73
|
+
```
|