Actions

Actions are a type of generic delegates that can be declared at instantion. Generic means that you need to specify a type when you declare it. Actions always return void and can take multiple parameters.

Action<T>
Action<T, T1, T2>

Now, we delete our SayGreeting delegate method and change it into Actions.

using System;

namespace FunctionalProgramming
{
    class Program
    {      
        static void Main(string[] args)
        {
            Action<string> sayGreeting;
            sayGreeting = delegate(string name)
            {
                Console.WriteLine(string.Format("Hello, {0}", name));
            };

            Console.WriteLine("What's your name?");
            var input = Console.ReadLine();
            sayGreeting(input);  
        }
    }
}

results matching ""

    No results matching ""