C#依頼簡単な使い方

3461 ワード

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace C04 

{ 

    public delegate void SayHi();



    class Program

    {

        static void TestDelegate(SayHi s)

        {

            s();

        }





        static void Main(string[] args)

        {

            SayHi s1 = new SayHi(Test);



            TestDelegate(s1);





            // .

            //   .

            // += .

            SayHi s = new SayHi(Test);

            s += Test1;

            s -= Test;

            s();



         

            //SayHi s = new SayHi(Test);

            //s += Test1;

            //s();



            //SayHi s = new SayHi(Test);

            //Test4(s); 



            Console.ReadKey();

        }



        static void Test4(SayHi s)

        {

            s();

        }





        static void Test()

        {

            Console.WriteLine("Test .");

        }



        static void Test1()

        {

            Console.WriteLine(" 2");

        }



    }

}