相性が悪いというのは無理ということではなく長くなるということです。
多次元配列は色々と対応が遅れている、というより対応する気がないように見えるので、時代遅れのデータ型としてなるべく使わないのがいいと思います。
代わりにジャグ配列やリストを使いましょう。
C#
1var cells = new int[,]
2{
3 { 0, 0, 0 },
4 { 0, 0, 0 },
5 { 1, 1, 0 },
6 { 0, 0, 0 },
7 { 1, 1, 1 },
8};
9var comparison = new int[] { 0, 0, 0 };
10int[] indexarr = Enumerable
11 .Range(0, cells.GetLength(0))
12 .Select(a => Enumerable
13 .Range(0, cells.GetLength(1))
14 .Select(b => cells[a, b]))
15 .Select((a, i) => a.SequenceEqual(comparison) ? i : -1)
16 .Where(a => a != -1)
17 .ToArray();
追記
ジャグ配列を使った場合
C#
1var cells = new int[][]
2{
3 new[] { 0, 0, 0 },
4 new[] { 0, 0, 0 },
5 new[] { 1, 1, 0 },
6 new[] { 0, 0, 0 },
7 new[] { 1, 1, 1 },
8};
9var comparison = new int[] { 0, 0, 0 };
10int[] indexarr = cells
11 .Select((a, i) => a.SequenceEqual(comparison) ? i : -1)
12 .Where(a => a != -1)
13 .ToArray();
追記
多次元配列の別解
C#
1var cells = new int[,]
2{
3 { 0, 0, 0 },
4 { 0, 0, 0 },
5 { 1, 1, 0 },
6 { 0, 0, 0 },
7 { 1, 1, 1 },
8};
9var comparison = new int[] { 0, 0, 0 };
10int[] indexarr = cells
11 .Cast<int>()
12 .Select((value, index) => new { value, index })
13 .GroupBy(a => a.index / cells.GetLength(1), a => a.value)
14 .Where(a => a.SequenceEqual(comparison))
15 .Select(a => a.Key)
16 .ToArray();
追記
多次元配列の別解
C#
1var cells = new int[,]
2{
3 { 0, 0, 0 },
4 { 0, 0, 0 },
5 { 1, 1, 0 },
6 { 0, 0, 0 },
7 { 1, 1, 1 },
8};
9var comparison = new int[] { 0, 0, 0 };
10int[] indexarr = Enumerable
11 .Range(0, cells.GetLength(0))
12 .Where(index => Enumerable
13 .Range(0, cells.GetLength(1))
14 .Select(a => cells[index, a])
15 .SequenceEqual(comparison))
16 .ToArray();
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2019/02/02 12:26
2019/02/02 13:46
退会済みユーザー
2019/02/02 15:53
2019/02/02 23:13
退会済みユーザー
2019/02/03 03:12
2019/02/03 03:36
2019/02/03 04:24
退会済みユーザー
2019/02/03 05:13