C# 从委托构造委托。新的代理指向什么?

C# 从委托构造委托。新的代理指向什么?,c#,reference,delegates,deep-copy,shallow-copy,C#,Reference,Delegates,Deep Copy,Shallow Copy,考虑以下几点: Action<int, T> a1 = new Action<int, T>(_insert); Action<int, T> a2 = new Action<int, T>(a1); 动作a1=新动作(\u插入); 动作a2=新动作(a1); a2指的是什么?它是a1,a1的浅拷贝还是a1的深拷贝?a2引用的是a1。以下是IL: .method private hidebysig static void Main() cil

考虑以下几点:

Action<int, T> a1 = new Action<int, T>(_insert);

Action<int, T> a2 = new Action<int, T>(a1);
动作a1=新动作(\u插入);
动作a2=新动作(a1);

a2指的是什么?它是a1,a1的浅拷贝还是a1的深拷贝?

a2
引用的是
a1
。以下是IL:

.method private hidebysig static void Main() cil managed
{
    .entrypoint
    .maxstack 3
    .locals init (
        [0] class [mscorlib]System.Action a1,
        [1] class [mscorlib]System.Action a2)
    L_0000: nop 
    L_0001: ldnull 
    L_0002: ldftn void WebTools.ConsoleTest.Program::Main()
    L_0008: newobj instance void [mscorlib]System.Action::.ctor(object, native int)
    L_000d: stloc.0 
    L_000e: ldloc.0 
    L_000f: ldftn instance void [mscorlib]System.Action::Invoke() #1
    L_0015: newobj instance void [mscorlib]System.Action::.ctor(object, native int)
    L_001a: stloc.1 
    L_0020: nop 
    L_0021: ret 
}
在#1,IL代码引用了
a1
的调用方法和实例
a1
本身


浅复制意味着复制了
a1
的内容,但没有复制任何内容。对象
a1
被视为黑盒。因此,
a2
将保持
a1
与GC相关的活动状态。

谢谢!p、 答:我仍在处理我的UI泛滥问题(来自和),一旦我解决了这个问题,我会通过评论告诉你:)对我来说,你的回答会引发更多的问题,而不是答案。我对这个IL清单的理解是,
b
[sic]引用了
a.Invoke
,而不是任何方法
a
引用。因此,它最接近于一个肤浅的复制品。说这是另一个间接层次可能更准确。@stakx,浅拷贝意味着a1的内容被拷贝,但没有被拷贝。对象a1被视为黑盒。因此a2将使a1在GC方面保持存活。@老实说,我对IL不熟悉。@stakx。。所以你认为这在某种程度上是不正确的(如果是这样的话,我会拒绝我接受的答案-只是为了不向so社区提供错误的答案)@usr,没错(尽管GC与这个问题基本无关)!感谢您在回答中添加了这一澄清。