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++;
}
}
}
C#_delegate - 调用列表 计算阶乘
最新推荐文章于 2024-11-09 13:58:10 发布