多次元配列、ジャグ配列を foreach で回す

using System;

public class TestArray {
    public static void Main() {
        int[,] xs = new int[,] { { 1, 2 }, { 3, 4 } };

        foreach (int x in xs) {
            Console.Write("{0} ", x);
        }
        Console.WriteLine();

        int[][] ys = new int[2][];
        ys[0] = new int[] { 10, 20 };
        ys[1] = new int[] { 30, 40 };
        foreach (int[] y in ys) {
            foreach (int yy in y) {
                Console.Write("{0} ", yy);
            }
        }
        Console.WriteLine();
    }
}

実行結果です。

1 2 3 4
10 20 30 40

参考: