T
Timothy
Hi,
I'm trying to understand how delegates work in C#. Lets say we have:
public delegate int MyDelegate(int a, int b);
public event MyDelegate MyEvent;
public int MyFunc(int a, int b) { return a+b; }
In order to assign the delegate to MyEvent (omitting some detail):
MyEvent += new MyDelegate(MyFunc);
In order to un-assign the delegate to MyEvent:
MyEvent -= new MyDelegate(MyFunc);
Now, my question is, why not use = instead of += and -=?
Eg, assign:
MyEvent = new MyDelegate(MyFunc);
Eg. un-assign:
MyEvent = null;
I hope I have the right idea
Thanks heaps in advance,
Tim.
I'm trying to understand how delegates work in C#. Lets say we have:
public delegate int MyDelegate(int a, int b);
public event MyDelegate MyEvent;
public int MyFunc(int a, int b) { return a+b; }
In order to assign the delegate to MyEvent (omitting some detail):
MyEvent += new MyDelegate(MyFunc);
In order to un-assign the delegate to MyEvent:
MyEvent -= new MyDelegate(MyFunc);
Now, my question is, why not use = instead of += and -=?
Eg, assign:
MyEvent = new MyDelegate(MyFunc);
Eg. un-assign:
MyEvent = null;
I hope I have the right idea
Thanks heaps in advance,
Tim.