๐Ÿ“šAction

class Program
{
    //static void Test1(string str, int aa) // ๋งค๊ฐœ๋ณ€์ˆ˜ ๋งž์•„์•ผ ํ•จ.
    static void Test1(string str)
    {
        Console.WriteLine("Test1 " + str);
    }

    static void Test2(string str)
    {
        Console.WriteLine("Test2 " + str);
    }

    static void Main(string[] args)
    {
        List<string> names = new List<string>();
        List<string> names2 = new List<string>();
        //Action<string, int> ac1 = Test2; // ์ด๊ฑฐ์•ˆ๋จ. ๋งค๊ฐœ๋ณ€์ˆ˜ ๋งž์•„์•ผ ํ•จ.
        Action<string> ac1 = Test2;
        Action<string> ac2 = delegate (string str)
        {
            Console.WriteLine("ac2 " + str);
        };
        Action<string, int> ac3 = (string str, int idx) =>
        {
            Console.WriteLine("{0} ac3 " + str, idx);
        };

        for (int i = 0; i < 1; i++)
        {
            names.Add("Bruce");
            names.Add("Alfred");
            names.Add("Tim");
            names.Add("Richard");

        }

        names.ForEach((x) =>
        {
            Console.WriteLine(x);
        });
        names.ForEach(Test1);
        names.ForEach(ac1);
        //names.ForEach(ac3); // ์ด๊ฑฐ์•ˆ๋จ. ๋งค๊ฐœ๋ณ€์ˆ˜ ์•ˆ๋งž์Œ.
    }
}

Last updated