回答編集履歴
2
見直しキャンペーン中
test
CHANGED
@@ -1,81 +1,41 @@
|
|
1
1
|
> 任意の行の配列を取り出せればstring.Joinでできると思うのですが…
|
2
2
|
|
3
|
-
|
4
|
-
|
5
3
|
`string.Join`しました(効率はわかりません)
|
6
|
-
|
7
4
|
[c# - How to get a dimension (slice) from a multidimensional array - Stack Overflow](https://stackoverflow.com/questions/4801990/how-to-get-a-dimension-slice-from-a-multidimensional-array) の丸パクリです^^;
|
8
5
|
|
9
|
-
|
10
|
-
|
11
|
-
```
|
6
|
+
```cs
|
12
|
-
|
13
7
|
using System.Collections.Generic;
|
14
|
-
|
15
8
|
using System.IO;
|
16
9
|
|
17
|
-
|
18
|
-
|
19
10
|
namespace Questions241081
|
20
|
-
|
21
11
|
{
|
22
|
-
|
23
12
|
internal class Program
|
24
|
-
|
25
13
|
{
|
26
|
-
|
27
14
|
private static void Main()
|
28
|
-
|
29
15
|
{
|
30
|
-
|
31
16
|
double[,] Values = { { 1.1, 2.2 }, { 3.3, 4.4 } };
|
32
17
|
|
33
|
-
|
34
|
-
|
35
18
|
using(var sw = new StreamWriter(@"test.csv", false))
|
36
|
-
|
37
19
|
{
|
38
|
-
|
39
20
|
for(var i = 0; i < Values.GetLength(0); ++i)
|
40
|
-
|
41
21
|
{
|
42
|
-
|
43
22
|
sw.WriteLine(string.Join(", ", Values.SliceRow(i)));
|
44
|
-
|
45
23
|
}
|
46
|
-
|
47
24
|
}
|
48
|
-
|
49
25
|
}
|
50
|
-
|
51
26
|
}
|
52
27
|
|
53
|
-
|
54
|
-
|
55
28
|
// c# - How to get a dimension (slice) from a multidimensional array - Stack Overflow
|
56
|
-
|
57
29
|
// https://stackoverflow.com/questions/4801990/how-to-get-a-dimension-slice-from-a-multidimensional-array
|
58
|
-
|
59
30
|
internal static class ArrayExtensions
|
60
|
-
|
61
31
|
{
|
62
|
-
|
63
32
|
public static IEnumerable<T> SliceRow<T>(this T[,] array, int row)
|
64
|
-
|
65
33
|
{
|
66
|
-
|
67
34
|
for(var i = array.GetLowerBound(1); i <= array.GetUpperBound(1); i++)
|
68
|
-
|
69
35
|
{
|
70
|
-
|
71
36
|
yield return array[row, i];
|
72
|
-
|
73
37
|
}
|
74
|
-
|
75
38
|
}
|
76
|
-
|
77
39
|
}
|
78
|
-
|
79
40
|
}
|
80
|
-
|
81
41
|
```
|
1
シンプル化
test
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
> 任意の行の配列を取り出せればstring.Joinでできると思うのですが…
|
2
|
+
|
3
|
+
|
4
|
+
|
1
5
|
`string.Join`しました(効率はわかりません)
|
2
6
|
|
3
7
|
[c# - How to get a dimension (slice) from a multidimensional array - Stack Overflow](https://stackoverflow.com/questions/4801990/how-to-get-a-dimension-slice-from-a-multidimensional-array) の丸パクリです^^;
|
@@ -5,8 +9,6 @@
|
|
5
9
|
|
6
10
|
|
7
11
|
```C#
|
8
|
-
|
9
|
-
using System;
|
10
12
|
|
11
13
|
using System.Collections.Generic;
|
12
14
|
|
@@ -26,23 +28,7 @@
|
|
26
28
|
|
27
29
|
{
|
28
30
|
|
29
|
-
double[,] Values = GetRandomArray();
|
30
|
-
|
31
|
-
//出力例(ランダム)
|
32
|
-
|
33
|
-
//0.88139194337716, 0.845414300377208, 0.425774484605423
|
34
|
-
|
35
|
-
//1.71903742790177, 1.55735241042327, 1.09685895922448
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
31
|
+
double[,] Values = { { 1.1, 2.2 }, { 3.3, 4.4 } };
|
40
|
-
|
41
|
-
//出力
|
42
|
-
|
43
|
-
//1, 2
|
44
|
-
|
45
|
-
//3, 4
|
46
32
|
|
47
33
|
|
48
34
|
|
@@ -62,33 +48,9 @@
|
|
62
48
|
|
63
49
|
}
|
64
50
|
|
65
|
-
|
66
|
-
|
67
|
-
// サイズ不定を表現しただけで本題とは関係ない
|
68
|
-
|
69
|
-
private static double[,] GetRandomArray()
|
70
|
-
|
71
|
-
{
|
72
|
-
|
73
|
-
var r = new Random();
|
74
|
-
|
75
|
-
var array = new double[r.Next(2, 5), r.Next(2, 5)];
|
76
|
-
|
77
|
-
for(var i = 0; i < array.GetLength(0); i++)
|
78
|
-
|
79
|
-
for(var j = 0; j < array.GetLength(1); j++)
|
80
|
-
|
81
|
-
array[i, j] = r.NextDouble() + i;
|
82
|
-
|
83
|
-
return array;
|
84
|
-
|
85
|
-
}
|
86
|
-
|
87
51
|
}
|
88
52
|
|
89
53
|
|
90
|
-
|
91
|
-
// 本題はこれ
|
92
54
|
|
93
55
|
// c# - How to get a dimension (slice) from a multidimensional array - Stack Overflow
|
94
56
|
|