1. 程式人生 > >C# Action 委託 + lambda 表示式

C# Action 委託 + lambda 表示式

using System;
using System.Collections;

public class Test
{
    static public Action A;
    static public Action<int> B;
    static public Action<int, string> C;
    static public Action<int, string, int> D;
    static public Action<int, string, int, string> E;

    static void Main()
    {
        A = () =>
            {
                Console.WriteLine("I'm A ");
            };

        B = (i) =>
            {
                Console.WriteLine("I'm B " + i);
            };

        C = (i, s) =>
            {
                Console.WriteLine("I'm C " + i + " " + s) ;
            } ;

        D = (i, s, j) =>
            {
                Console.WriteLine("I'm D " + i + " " + s + " " + j) ;
            } ;

        E = (i, s, j, t) =>
            {
                Console.WriteLine("I'm E " + i + " " + s + " " + j + " " + t);
            };

        A();
        B(1);
        C(1, "a");
        D(1, "a", 2);
        E(1, "a", 2, "b");
               
        Console.ReadKey();
    }
}