For one of the classes I have, it’s necessary to implement a clone method. So I’m trying to figure out if I need to copy the events of the class by reference or by value.
For example, let say you have the following:
Ball ballOne = new Ball();
ballOne.Bounce += new EventHandler(ballOne_Bounce);
Ball ballTwo = ballOne.Clone();
How should I write the Clone method so the Bounce event for ballTwo is triggered?
Thanks,
Tyler
Delegates are reference types in .NET, and they’re also immutable, so “reference vs. value” isn’t meaningful. If you want to copy the event delegate, just copy it (i.e., copy the reference).