fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. // LINQで二次元ジャグ配列をコピーする
  8.  
  9. namespace Linq2ch918
  10. {
  11. class Program
  12. {
  13. static void Main(string[] args)
  14. {
  15. int[][] a1 = { new int[]{ 1, 2, 3 }, new int[]{ 4, 5 }, new int[]{ 6, 7, 8, 9, 10 } };
  16. int[][] a2 = { new int[3], new int[2], new int[5] };
  17. Enumerable.Range(0, a1.Length).SelectMany(i => Enumerable.Range(0, a1[i].Length), (x, y) => new { x, y })
  18. .Select(xy => new { xy.x, xy.y }).Select(xy => { return a2[xy.x][xy.y] = a1[xy.x][xy.y]; }).ToList(); // 即時実行
  19. foreach (var i in a2) {
  20. foreach (var j in i)
  21. Console.Write(j + " ");
  22. Console.WriteLine();
  23. }
  24. }
  25. }
  26. }
Success #stdin #stdout 0.06s 24080KB
stdin
Standard input is empty
stdout
1 2 3 
4 5 
6 7 8 9 10