回答編集履歴

2

ZIPの作り方を追記

2017/05/31 05:08

投稿

Tokeiya3
Tokeiya3

スコア260

test CHANGED
@@ -43,3 +43,103 @@
43
43
 
44
44
 
45
45
  ```
46
+
47
+
48
+
49
+ ----
50
+
51
+ ココより追記
52
+
53
+
54
+
55
+ 無いなら作ろうって感じでひとつ。
56
+
57
+
58
+
59
+ ```csharp
60
+
61
+
62
+
63
+ using System;
64
+
65
+ using System.Collections.Generic;
66
+
67
+ using System.Linq;
68
+
69
+
70
+
71
+ namespace ConsoleApp8
72
+
73
+ {
74
+
75
+ static class MyExtend
76
+
77
+ {
78
+
79
+ public static IEnumerable<TResult> MyZip<T1, T2, TResult >(this IEnumerable<T1> first, IEnumerable<T2> second,Func<T1,T2,TResult> resultSelector)
80
+
81
+ {
82
+
83
+ if(first==null) throw new ArgumentNullException("first");
84
+
85
+ if(second==null) throw new ArgumentNullException("second");
86
+
87
+ if(resultSelector==null)throw new ArgumentNullException("resultSelector");
88
+
89
+
90
+
91
+
92
+
93
+ using (var f = first.GetEnumerator())
94
+
95
+ using (var s=second.GetEnumerator())
96
+
97
+ {
98
+
99
+ while (f.MoveNext()&&s.MoveNext())
100
+
101
+ {
102
+
103
+ yield return resultSelector(f.Current, s.Current);
104
+
105
+ }
106
+
107
+ }
108
+
109
+
110
+
111
+ }
112
+
113
+ }
114
+
115
+
116
+
117
+ class Program
118
+
119
+ {
120
+
121
+ static void Main(string[] args)
122
+
123
+ {
124
+
125
+ int[] a = new int[] { 1, 2, 3 };
126
+
127
+ int[] b = new int[] { 6, 5, 4 ,5,6};
128
+
129
+ int[] diff = a.MyZip(b, (x, y) => y - x).ToArray();
130
+
131
+
132
+
133
+ }
134
+
135
+ }
136
+
137
+ }
138
+
139
+
140
+
141
+ ```
142
+
143
+
144
+
145
+

1

評価が逆になってたw

2017/05/31 05:07

投稿

Tokeiya3
Tokeiya3

スコア260

test CHANGED
@@ -30,17 +30,7 @@
30
30
 
31
31
 
32
32
 
33
- int[] diff = a.Zip(b, (x, y) => x - y).ToArray();
33
+ int[] diff = a.Zip(b, (x, y) => y - x).ToArray();
34
-
35
-
36
-
37
- foreach (var i in diff)
38
-
39
- {
40
-
41
- Console.WriteLine(i);
42
-
43
- }
44
34
 
45
35
  }
46
36