Quantcast
Channel: Is multicast delegate create new reference for each chaining? - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Is multicast delegate create new reference for each chaining?

$
0
0

Is multicast delegate create new reference for each chaining? or its a value type (MSDN says otherwise)? I don't understand, please take look at the following code.

using System;
class TestClass
{
    static void Main()
    {
        Action origin = new Action(() => { Console.WriteLine("1st line"); });
        Action copyFromOrigin;

        copyFromOrigin = origin;
        origin += new Action(() => { Console.WriteLine("2nd line"); });

        copyFromOrigin.Invoke();

        //result is "1st line", why the "2nd line" is missing? 
        //shouldn't the copyFromOrigin is referencing the origin?
        Console.ReadKey();
    }
}

Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>