这是在我的其他问题中提到的,我认为将它添加到记录可能会有用。在以下程序中,哪些(如果有)本地定义的委托在对Work方法的调用之间进行缓存,而不是每次都从头开始创建?哪些(如果有)本地定义的委托在方法调用之间被缓存?
namespace Example
{
class Dummy
{
public int age;
}
class Program
{
private int field = 10;
static void Main(string[] args)
{
var p = new Program();
while (true)
{
p.Work();
}
}
void Work()
{
int local = 20;
Action a1 =() => Console.WriteLine(field);
Action a2 =() => Console.WriteLine(local);
Action a3 =() => Console.WriteLine(this.ToString());
Action a4 =() => Console.WriteLine(default(int));
Func<Dummy, Dummy, bool> dummyAgeMatch = (l, r) => l.age == r.age;
a1.Invoke();
a2.Invoke();
a3.Invoke();
a4.Invoke();
dummyAgeMatch.Invoke(new Dummy() { age = 1 }, new Dummy(){ age = 2 });
}
}
}
谢谢 - 这是小说! – xyz 2009-01-15 19:15:24