using System;

namespace Délégation_générique
{

    // public delegate T Transformer<T>(T arg);
    class Util
    {
        public static void Traitement<T>(T[] values, Func<T,T> 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();
        }
    }

}
