Home >

Sample Code of Action<T>

7. October 2009

Just some sample code of passing a action lambda expression into a method.

 

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

namespace Func
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] weekDays = {"Sun", 
                                    "Sat", 
                                    "Mon", 
                                    "Tue", 
                                    "Wed", 
                                    "Thu", 
                                    "Fri"};
            
            Display3(weekDays, s => Console.WriteLine(s + "hello"));
            Console.ReadLine();

        }

        private static void Display3<T>(T[] name, Action<T> action)
        {
            foreach (T s in name)
            {
                action(s);
            }
        }

    }
}
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5