Estuve jugando con los Métodos Extendidos en C# 3.0, y la verdad que esta feature hace que el código sea más legible.

string[] terminos = new string[] { "gurí", "guaina", "tereré", "mate" };

            foreach (var item in terminos)
                Console.WriteLine(item);

Utilizando estas extensiones de métodos:

public delegate void VoidsHandler<T>(T param);

    public static class DarioExtend
    {
        public static void ApplyToAll<T>(this IList<T> lista, VoidsHandler<T> handler)
        {
            foreach (var item in lista)
            {
                handler(item);
            }
        }

        public static void WriteLine<T>(this IList<T> lista)
        {
            foreach (var item in lista)
            {
                Console.WriteLine(item);
            }

        }
    }

La forma de imprimir podría cambiarse por:

terminos.ApplyToAll(item => Console.WriteLine(item));

ó por esto:

 terminos.WriteLine();
Tagged with:
 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>