C#_delegate

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Delegate
{
    public delegate int Myfunction(ref int refCount);

    class Program
    {
        static void Main(string[] args)
        {

            Myfunction[] mfs = { MethodA, MethodA, MethodA, MethodA, MethodA};
            
            Myfunction del = (Myfunction)Myfunction.Combine(mfs);

            int refCount = 1;

            int result = 1;

            foreach(Myfunction mf in del.GetInvocationList())
            {
                result = result* mf(ref refCount);
            }
            Console.WriteLine("del.GetInvocationList(): " + del.GetInvocationList().Length);
            Console.WriteLine("result: "+result);

            Console.ReadLine();
        }

        public static int MethodA(ref int refCount)
        {

            return refCount++;
        }      
    }
}


原文地址:https://www.cnblogs.com/MarchThree/p/3720451.html