In the following code, does ptrcall point…
- to 2 places on the heap with methods
obj.callMeandobj1.callMe; or… -
to 1 place that contains both methods
obj.callMe,obj1.callMewithin it?public delegate void CallEveryOne(); private void Form1_Load(object sender, EventArgs e) { public CallEveryOne ptrcall=null; public Form2 obj = new Form2(); public Form3 obj1 = new Form3(); obj.Show(); obj1.Show(); ptrcall += obj.CallMe; ptrcall += obj1.CallMe; }
ptrcallis, like basically all delegates from .NET 2.0 onward, a multicast delegate. That is, it keeps its own internal list of methods that it refers to. MSDN has the following to say onMulticastDelegate:So, in your terminology, the answer is most likely that
ptrcallpoint to 2 place on heap.But why does this implementation detail matter at all?
P.S.: You could call
ptrcall.GetInvocationList()and see what you get back. I only recommend this to you for toying around and getting to know delegates better; don’t do it in production code unless you really have to.