委托动态注入一段代码
using System;
using System.Collections.Generic;
using System.Text;
namespace DelegateTest
{
public class Writer
{
public string Text;
public int Counter;
public void Dump()
{
Console.WriteLine(Text);
Counter++;
}
}
class Program
{
public delegate void Delegate1();
static void Repeat10Times(Delegate1 somework)
{
for(int i=0;i<10;i++)
somework();
}
static void Main(string[] args)
{
Writer writer=new Writer();
writer.Text="Hello";
Repeat10Times(writer.Dump);
Console.WriteLine(writer.Counter);
Console.Read();
}
}
}