Esempio n. 1
0
        static void Main(string[] args)
        {
            List <int> myLista = new List <int>()
            {
                1, 3, 2, 5, 2, 1, 6
            };
            IEnumerator <int> myEnumerator = myLista.GetEnumerator();

            Console.WriteLine(myEnumerator.Current);
            Agrupador <int, bool> myAgrupador = new Agrupador <int, bool>();

            int[]    numbers = new int[] { 2, 4, 5, 7, 9, 10, 14, 132 };
            Person[] persons = new Person[] {
                new Person("Juan", 20),
                new Person("Ana", 19),
                new Person("Alberto", 23),
                new Person("Carlos", 20),
                new Person("Chucho", 19),
                new Person("Maria", 18)
            };



            Console.WriteLine("Agrupando pares e impares...-----------------------------");
            Print <int, bool>(myAgrupador.Agrupa(numbers, new ParitySelector()));
            Console.WriteLine();



            Agrupador <int, int> otroAgrupador = new Agrupador <int, int>();

            Console.WriteLine("Agrupando por cantidad de digitos...-----------------------------");
            Print <int, int>(otroAgrupador.Agrupa(numbers, new NumerOfDigitsSelector()));
            Console.WriteLine();



            Agrupador <Person, char> myOtro = new Agrupador <Person, char>();

            Console.WriteLine("Agrupando por primera letra...-----------------------------");
            Print <Person, char>(myOtro.Agrupa(persons, new FirstLetterSelector()));
            Console.WriteLine();



            Agrupador <Person, int> otroMas = new Agrupador <Person, int>();

            Console.WriteLine("Agrupando por edad...-----------------------------");
            Print <Person, int>(otroMas.Agrupa(persons, new AgeSelector()));
            Console.WriteLine();



            Console.ReadLine();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            List <Persona> listaPersonas = new List <Persona>();

            listaPersonas.Add(new Persona("Carlos", new DateTime(2005, 3, 2)));
            listaPersonas.Add(new Persona("Juan", new DateTime(2005, 12, 5)));
            listaPersonas.Add(new Persona("Jose", new DateTime(1999, 4, 8)));

            Agrupador <Persona> myAgrupador = new Agrupador <Persona>();

            IEnumerable <IGrupo <Persona> > enumerable = myAgrupador.Agrupa(listaPersonas, new LongitudNombreSelector());

            foreach (var el in enumerable)
            {
                Console.WriteLine(el.Llave);
                foreach (var otherel in el)
                {
                    Console.WriteLine(otherel.Nombre);
                }
            }
        }