Commissioned _deleget

the System the using; 
the using the System.Collections.Generic; 
the using the System.Linq; 
the using the System.Text; 
the using System.Threading.Tasks; 

/ * 
 
            // delegate type provided by the framework 
            // without return of 
            Action act0 = () => Console .WriteLine ( "no parameters without return"); 
            the Action <int> X = ACT1 => Console.WriteLine ( "without return parameters. 1"); 
            the Action <int, int> ACT2 = (X, Y) => Console.WriteLine ( "without return reference 2"); 
            // return has a 
            Func <string> func0 = () => " there are no arguments back"; 
            Func <int, String> X = func1 => "parameter has returned. 1"; 
            Func <int, double, string> func2 = (x, y) => " multi-parameter has returned";

     * / 

Namespace commissioned _deleget 
{ 

    // 1, declare a delegate 
    // method to declare a template modification plus deleget
    // Method is to escape into a class, the class specifying usage rules, such as the back, the reference number or type of 

    public nRNC the delegate void (); 
    public int hRnC the delegate (); 
    the delegate hRhC String (String A, B int) ; 


    class Program 
    { 
        // 2, the method calls for the delegate defines 
        Private static void for_nRnC_1 () {Console.WriteLine ( "for_nRnC_1");} 
        Private static void for_nRnC_2 () {Console.WriteLine ( "for_nRnC_2");} 
        Private static for_hRhC String (String A, V int) 
        { 
            String TEMP = null; 
            for (int I = 0; I <V; I ++) 
            { 
                TEMP = A +; 
            } 
            return TEMP; 
        }


        the Main void static (String [] args) 
        { 
            //. 3, delegate instantiation object, which method comprises a call list 

            // no parameters without return 
            nRNC myDeleget_nRnC nRNC new new = (for_nRnC_1); 
            // parameters have returned there, 
            hRhC myDeleget_hRhC = hRhC new new (for_hRhC); 

            //. 4, use (execution) delegate 

            // nRNC 
            myDeleget_nRnC.Invoke (); 

            // hRhC 
            String myDeleget_hRhC RET = ( "Batu",. 5); 
            Console.WriteLine (RET); 

            // multimode delegate, the method returns the last value of the return value 
            myDeleget_nRnC + = for_nRnC_2; 
            myDeleget_nRnC - = for_nRnC_2; 

            Console.Read (); 
        } 
    }

    // Event _Event 

    class EventTest 
    { 
        void doSomething () 
        { 
            ForEvent new new ForEvent myTest = (); 
            myTest.shijian + = MyTest_shijian; 
            //myTest.shijian = MyTest_shijian; 
            //myTest.shijian (); 
            myTest.weituo = MyTest_shijian; 
            myTest.weituo (); 
        } 

        Private void MyTest_shijian () {;;;} 
    } 

    class ForEvent 
    { 
        // this is an attribute that can be assigned directly and perform 
        // class corresponding to the method of directly exposed inside out 
        public nRnC weituo {set ; GET;} 

        // this is an event that can only + = or - = and can not be called from outside 
        // event is used as a control object permissions,
        // only, this event can not perform to the hanging method or delete methods on the outside, does not alter the original method 
        public Event nRNC Shijian; 
    } 
}

  

Guess you like

Origin www.cnblogs.com/Jeely/p/11003516.html