using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Syslab.Sample.Ex07
{
    class Program
    {
        static object locker = new object();
        static char[] name = "Anderson Santos Gusmão".ToArray<char>();
        static int[][] array = new int[][] { new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 }, new int[] { 7, 8, 9 } };

        static void Main(string[] args)
        {
            Parallel.For(0, name.Length, i => For(i));
            Console.WriteLine(System.Environment.NewLine);

            Parallel.For(0, array.Length, i =>
            {
                Parallel.For(0, array[i].Length, j =>
                {
                    lock (locker)
                        array[i][j] *= 5;
                });
            });

            for (int i = 0; i < array.Length; i++)
                for (int j = 0; j < array[i].Length; j++)
                    Console.Write(string.Format("{0},", array[i][j]));

            Console.WriteLine(System.Environment.NewLine);
        }

        static void For(int i)
        {
            Console.Write(name[i]);
        }
    }
}
