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

namespace DélégationEtPassageParValeur
{
    public delegate int Transformer(int x);
    class Util
    {
        public static void Traitement(int[] values, Transformer t)
        {
            for (int i = 0; i < values.Length; i++)
                values[i] = t(values[i]);
        }
    }

    class Program
    {
        static int Square(int x) { return x * x; }
        static int Negate(int x) { return x * -1; }
        static void Main(string[] args)
        {
            int[] valeurs = { 1, 2, 3 };
            Util.Traitement(valeurs, Square); // Hook in the Square method
            foreach (int i in valeurs)
                Console.Write(i + " "); // 1 4 9
            Util.Traitement(valeurs, Negate); // Hook in the Square method
            foreach (int i in valeurs)
                Console.Write(i + " "); // -1 -4 -9
            Console.ReadKey();
        }
    }
}
